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

Rikki Cattermole via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 7 05:28:35 PDT 2015


On 8/07/2015 12:26 a.m., "Per =?UTF-8?B?Tm9yZGzDtnci?= 
<per.nordlow at gmail.com>" wrote:
> I'm currently developing a high-level wrapper for FFMPEG at
>
> https://github.com/nordlow/justd/blob/master/tests/t_ffmpeg.d
>
> My question now becomes how to most easily wrap the iteration over
> streams at
>
> https://github.com/nordlow/justd/blob/master/tests/t_ffmpeg.d#L150
>
> https://github.com/nordlow/justd/blob/master/tests/t_ffmpeg.d#L152
>
> in a nice D-style range interface.
>
> Do I have to allocate a new D array and copy the `AVStream*` elements
> into that or is there a convenience wrapper for constructing a lazy
> range from a C style Array-pointer plus array-length?
>
> Note that the elements of the C array are pointers to structs, in this
> case instances of `AVStream`. This, of course, complicates the matter
> with regard to GC-safety.
>
> Comments on that please :)

size_t count;
AVStream* thePtr;
AVStream[] array = thePtr[0 .. count];

That should work.


More information about the Digitalmars-d-learn mailing list