Wrapping a C-style Array (Pointer + Length) in a Range Interface

John Colvin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 7 06:28:22 PDT 2015


On Tuesday, 7 July 2015 at 12:33:23 UTC, Per Nordlöw wrote:
> On Tuesday, 7 July 2015 at 12:29:04 UTC, Rikki Cattermole wrote:
>> size_t count;
>> AVStream* thePtr;
>> AVStream[] array = thePtr[0 .. count];
>>
>> That should work.
>
> Thanks.
>
> Will that reuse the existing allocate memory at `thePtr` for 
> internal storage of the D array? If so how is the GC aware of 
> this memory?
>
> Is there any tutorials, reference documentation, etc on these 
> matters?

Slicing never* allocates a new array. The GC is only aware of 
memory it allocates itself and memory it is explicitly told about 
(see core.memory)

Slicing pointers etc. should all be covered in 
http://dlang.org/arrays.html, 
http://dlang.org/d-array-article.html, 
http://ddili.org/ders/d.en/arrays.html and 
http://ddili.org/ders/d.en/slices.html

*unless you're using operator overloading, in which case it can 
do anything of course


More information about the Digitalmars-d-learn mailing list