From Go Your Own Way (Part Two: The Heap):
import core.stdc.stdlib;
`// Allocate a block of untyped bytes that can be managed`
`// as a slice.`
`void[] allocate(size_t size)`
`{`
`// malloc(0) is implementation defined (might return null `
`// or an address), but is almost certainly not what we want.`
`assert(size != 0);`
`void* ptr = malloc(size);`
`if(!ptr) assert(0, "Out of memory!");`
`// Return a slice of the pointer so that the address is coupled`
`// with the size of the memory block.`
`return ptr[0 .. size];`
}
T[] allocArray(T)(size_t count)
{
// Make sure to account for the size of the
// array element type!
return cast(T[])allocate(T.sizeof * count);
}
What is the equivalent for higher dimensional arrays?