DIP 1025--Dynamic Arrays Only Shrink, Never Grow--Community Review Round 1

Jonathan M Davis newsgroup.d at jmdavisprog.com
Mon Nov 11 17:28:09 UTC 2019


On Monday, November 11, 2019 10:12:13 AM MST Ola Fosheim Grøstad via 
Digitalmars-d wrote:
> On Monday, 11 November 2019 at 17:00:07 UTC, Steven Schveighoffer
>
> wrote:
> > No, you are misunderstanding a lot here.
>
> This is nitpicking.
>
> If you are going to have a good story with interfacing with C++
> libraries and frameworks... you don't want this to fail
> accidentally:
>
> ownerpointer = normalize(initialize(allocate()))
>
> Where normalize is a D function that calls other GC library code
> that is well-behaving, except the one that accidentally grows the
> slice because it works in the library-author's pure GC code.
>
> You have to be able to call GC code even if you want to modify
> non-GC memory.
>
>
> Anyway, it also isn't true that Dynamic Arrays don't have a type.
> It isn't untyped. But the typesystem it uses is completely
> different from the rest of the language.
>
> It appears to be quasi-dynamic effects based, whereas the rest of
> the language is mostly static strongly typed. Meaning, the type
> changes as you use it. Does any other object in D do that?

How on earth do D dynamic arrays change their type? int[] is always int[]. I
believe that the bit that Steven is talking about with regards to them being
untyped is that inside druntime, it uses void*, because the code isn't
templated - which arguably is something that should be fixed. Outside of
druntime's innards though, a dynamic array always has the same type. All it
really is is a struct containing a pointer and a size_t for length.

- Jonathan M Davis






More information about the Digitalmars-d mailing list