Reputation: 135
I use Visual Studio 2008. I have dynamically declared the variable big_massive:
unsigned int *big_massive = new unsigned int[1073741824]
But, when I tried to debug this program, I got following error: Invalid allocation size: 4294967295 bytes. I hope there are any path to avoid such error? Thank you!
Upvotes: 3
Views: 2893
Reputation: 5114
Upvotes: 2
Reputation: 113242
Amount of virtual memory per process on 32bit Windows system or 64bit Windows system running a 32bit program (WoW64): 2147483648 Amount of memory needed to hold an array of 1073741824 4-byte unsigned integers: 4294967296 Can't possibly fit in the amount of memory available, so it's an invalid allocation.
Upvotes: 3
Reputation: 206689
That allocation is simply not possible on 32bit x86 systems with sizeof(int)==4
(you are requesting 4GB). A process's total address space is limited to 4GB, and the process itself is usually limited to less than that (2GB or 3GB for 32bit Windows depending on boot.ini
settings and the Windows edition, not sure which limit applies for 32bit processes on 64bit Windows, but 4GB is simply not possible).
For the 64bit case, you'd need to have 4GB of virtual memory available to back that allocation for it to succeed.
Upvotes: 6