Is this correct ? This is compiled with g++ (3.4) sucessfully.
int main()
{
int x = 12;
char pz[x];
}
Allocating arrays with variable length on the stack is a good idea, because it fast and doesn't fragment the memory. But C++ Standard unfortunately doesn't support it. You could do this by using template wrapper to alloca function. But using alloca is not really a standard conforming.
Standard way is to use std::vector with custom allocator if you want to avoid memory fragmentation and speedup memory allocations. Take a look on boost::pool_alloc for a good sample of fast allocator.