I am doing some extremely large array processing. I do a global declaration of:
`float array[200][1600][811];`
When I build my solution in MS Visual Studio 2010, I get the following error
LINK : fatal error LNK1248: image size (F85C8000) exceeds maximum allowable size (80000000)
Now, I am aware this amounts to about 1 GB of program memory. But this declaration worked for a declaration of float [50][1600][811]
which amounts to 250 MB. I know the default stack size is very limited.
There are a couple of things I have already tried. I increased the stack size in VS through Properties -> Linker -> Stack reserved size. This didnt help. I changed my executable to run in x64 mode (which is said to address upto 2GB memory!). This didnt help either.
I do not wish to do a malloc
on the array because I know for sure I need them in my code. I had to make them global declarations so that I can avail the stack/heap memory. If I declare them inside my Main ()
, it gives me error of memory overflow.
Any pointers would be greatly appreciated. Thanks.
It appears that even when you're building an x64 executable, the linker has limits more appropriate for an x86 build. Not much you can do about that.
The only solution is to allocate it from the heap. This should be usable in the same way as your original declaration.
If you are
malloc
adverse, you have two immediately obvious possibilties. C++11 has a nice array type which might help:Or you could consider using
std::vector
with a loop to initialise all the values correctly: