The OpenD Programming Language

mallocSlice

A trivial wrapper around C's malloc that creates a D slice. It multiples n by T.sizeof and returns the slice of the pointer from 0 to n.

Please note that the ptr might be null - it is your responsibility to check that, same as normal malloc. Check ret is null specifically, since ret.length will always be n, even if the malloc failed.

Remember to free the returned pointer with core.stdc.stdlib.free(ret.ptr);

I strongly recommend you simply use the normal garbage collector unless you have a very specific reason not to.
T[]
mallocSlice
(
T
)
(
size_t n
)

See Also

Meta