Is there an easy way to convert a pointer to malloc'd memory to an array?
Marco Leise via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed May 25 04:08:11 PDT 2016
Am Tue, 24 May 2016 20:58:14 +0000
schrieb Gary Willoughby <dev at nomad.so>:
> On Tuesday, 24 May 2016 at 18:43:22 UTC, Adam D. Ruppe wrote:
> > On Tuesday, 24 May 2016 at 18:42:41 UTC, Gary Willoughby wrote:
> >> I have a T* pointer to the start of a malloc'd chunk of
> >> memory, the type T and the number of T's stored in the chunk.
> >>
> >> Is there an efficient way of converting this information to a
> >> D array of type T[] or even T[n]?
> >
> > Slice it:
> >
> > T[] = t[0 .. n];
>
> That! ...is amazing!
How did you _ever_ read structs from files without this
knowledge?
--
Marco
More information about the Digitalmars-d-learn
mailing list