Allocating a fixed-size array on the heap
downs
default_357-line at yahoo.de
Wed Jan 30 09:34:59 PST 2008
David Wilson wrote:
> As I understand it, a variable of the type float[4] will already be a
> reference pointing to the heap.
No.
Because the size is part of the type (float[4]), there's no reason to store it separately.
And since float[4] is a value type, not a reference type like ordinary arrays, it's allocated on the stack.
The trouble is, because you can allocate dynamic arrays via the `new T[n]` syntax (which, incidentally, has nothing to do with static arrays), there's no syntax left over for allocating float[4] on the heap.
However, since static arrays are a stunted data type anyway (can't return them, can't ref them), I recommend that they only be used wrapped in a struct, where they can be handled safely.
--downs
More information about the Digitalmars-d
mailing list