Re: Cast ptr/len to D-style array

2019-05-04 Thread James Blachly via Digitalmars-d-learn
On 5/3/19 5:42 AM, Ali Çehreli wrote: On 05/02/2019 08:21 PM, James Blachly wrote: On 5/2/19 4:05 PM, ag0aep6g wrote: Just slice the pointer with the length: int* ptr; size_t len; int[] arr = ptr[0 .. len]; Perfect thanks. I searched but without using the magic word "slice" I

Re: Cast ptr/len to D-style array

2019-05-03 Thread Ali Çehreli via Digitalmars-d-learn
On 05/02/2019 08:21 PM, James Blachly wrote: On 5/2/19 4:05 PM, ag0aep6g wrote: Just slice the pointer with the length: int* ptr; size_t len; int[] arr = ptr[0 .. len]; Perfect thanks. I searched but without using the magic word "slice" I couldn't find meaningful results.

Re: Cast ptr/len to D-style array

2019-05-02 Thread James Blachly via Digitalmars-d-learn
On 5/2/19 4:05 PM, ag0aep6g wrote: Just slice the pointer with the length:     int* ptr;     size_t len;     int[] arr = ptr[0 .. len]; Perfect thanks. I searched but without using the magic word "slice" I couldn't find meaningful results. Thanks again.

Re: Cast ptr/len to D-style array

2019-05-02 Thread ag0aep6g via Digitalmars-d-learn
On 02.05.19 22:03, James Blachly wrote: I work a lot with C functions, many of which yield pointer + length. Is there a way to cast this or materialize a D-style array backed by the already allocated data (with length) to avoid copies which slow things down? Just slice the pointer with the

Cast ptr/len to D-style array

2019-05-02 Thread James Blachly via Digitalmars-d-learn
I work a lot with C functions, many of which yield pointer + length. Is there a way to cast this or materialize a D-style array backed by the already allocated data (with length) to avoid copies which slow things down? I recognize memory management is a complication. Typically, I would be