Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dlang: Construct an array from a pointer and length

Tags:

arrays

pointers

d

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

like image 799
porton Avatar asked Sep 09 '26 00:09

porton


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
like image 156
porton Avatar answered Sep 12 '26 12:09

porton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!