How to encapsulate an existing array using D2's phobos std.range

68 views Asked by At

I would like to encapsulate an existing data array ( created by Python's Numpy Lib ) into an Array like object in the D2 Language... without having to copy the array data... I already use Python's cTypes Lib to make a DLL call, passing array lengths and data pointers.. But I am still copying the array data to place it into a native D2 array. It appears as if may be possible not to need to copy the array data by employing the phobos library's std.range class.. This array encapsulation pattern would be quite common... I an new to both D as well as this range class abstraction... It would be great to have D2 example code as to how this would be done.

1

There are 1 answers

0
Maksim Zholudev On

You can slice the pointer. This operation will return a D array:

int *p = /*some initializer*/;
int[] a = p[0..N];