Dlang: Construct an array from a pointer and length

Viewed 163

I have a pointer and length. How to get a dynamic array from them?

1 Answers

Let ptr is a pointer and len is a length, then it is easy as the following:

ptr[0..len]

Note that this does not copy the array, but uses data in-place.

If you want to copy the array, use

ptr[0..len].dup

or

ptr[0..len].idup
Related