Stack-allocated arrays

dsimcha dsimcha at yahoo.com
Tue Nov 11 10:41:11 PST 2008


== Quote from Frits van Bommel (fvbommel at REMwOVExCAPSs.nl)'s article
> A workaround you could use:
> -----
> // N == your "arbitrary but reasonable value", use whatever you want.
> // (Add "= void" to next line to avoid initialization if you prefer)
> T[N] stackbuf;	        // don't use this except in next line
> T[] buf = stackbuf;     // Set reference to stack buffer
> // Shrink to smaller size or heap-allocate bigger size:
> buf.length = length;
> -----

If I'm going to do something this hackish and ugly, I may as well just use alloca
explicitly.



More information about the Digitalmars-d mailing list