Yes, you can declare this array on the stack (with a little extra work), but that is not sensible.
There is no justifiable reason why the array should be on the stack.
The overhead associated with the dynamic allocation of a single array is incorrect (you can say βzeroβ), and the smart pointer will safely take care that there is no memory leak if this bothers you. The allocated stack memory is no different from the memory allocated by the heap (except for some caching effects for small objects, but they do not apply here).
In any case, just do not do it.
If you insist that you have to allocate an array on the stack, you first need to reserve 32 megabytes of stack space (preferably a little more). To do this, using Dev-C ++ (which assumes Windows + MingW), you need to either set a reserved stack size for your executable file using compiler flags such as -Wl,--stack,34000000 (this is slightly larger than 32MiB), or create a stream (which allows you to specify the reserved stack size for this stream).
But really, again, just don't do it. There is nothing wrong with dynamically allocating a huge array.
Damon source share