Setting array length to 0 discards reserved allocation?
John Colvin via Digitalmars-d
digitalmars-d at puremagic.com
Tue Jul 29 01:47:11 PDT 2014
On Tuesday, 29 July 2014 at 07:46:34 UTC, Andrew Godfrey wrote:
> On Sunday, 27 July 2014 at 05:51:46 UTC, Jakob Ovrum wrote:
>> On Saturday, 26 July 2014 at 23:06:02 UTC, Andrew Godfrey
>> wrote:
>>> Thereafter can come sub-slice examples and so on.
>>> Does this make sense?
>>
>> Yes, the reference documentation is pretty terrible with
>> naming of various array concepts.
>>
>> IIRC, when this was discussed in the past, a majority seemed
>> to be in favour of using "slice" and "dynamic array" for their
>> respective concepts instead of the current situation, but I
>> also remember there was some opposition (for reason I can't
>> remember). A pull request updating the documentation to use
>> slice/dynamic array might weed them out ;)
>
> I gave this a try, and overall it looks like an improvement,
> but I think we need another name than "slice". The reason is
> that the slice operator is a distinct thing and interacts with
> the "slice" in strange ways. When I next get time I'll try
> updating it to use the term "array reference". That is:
>
> int[] a; // defines an array reference, a
> int[3] b;
> a = b[1..3]; // updates the array reference a to refer to a
> slice of b
You can look at it like this: There are no builtin dynamic arrays
in D, there are only slices (windows on to arbitrary memory) and
static arrays (a block of stack memory, treated a value type).
What you choose your slice to be a window on is your own business.
int[] a = new int[10]; //a window on to some new gc memory
int[3] b; //a static array
a = b[1 .. 3]; //a window on to part of of b
a = (cast(int*)core.stdc.stdlib.malloc(10*int.sizeof))[0 .. 10];
//a window on to some new memory on the C heap.
More information about the Digitalmars-d
mailing list