How can I make this work?

rikki cattermole rikki at cattermole.co.nz
Sun Feb 28 08:45:23 UTC 2021


On 28/02/2021 8:05 PM, Jack wrote:
> int[] arr = [1, 2, 3];
size_t l = cast(size_t)arr.ptr;

Okay, so far so good

> int[] a = cast(int[]) cast(void*) l;

Umm, you haven't specified a length?

int[] a = (cast(int*)l)[0 .. 3];

If the callback is being called (in effect under the current stack frame 
and won't escape), I would wrap the data you need in a struct and pass 
that to it instead by pointer. No need for heap allocation and gives a 
way to pass more complex data should the need arise.


More information about the Digitalmars-d-learn mailing list