Click here to Skip to main content
15,112,662 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:

Hi,

I have a question about dynamic memory allocation.

Is there a limitation (except hardware - available RAM) on the amount of memory that can be allocated?

can i allocate 1MB in a loop 2000 times resulting in a 2GB of memory allocation?

I have a faint memory that says that there is a 2GB limit of memory allocation per application

can i over ride this limit? how?

Thanks!

dj4400
Posted
Comments
   
I answered, but am just curious: was that so hard to find out in the documentation of the OS in question.
You should tag your platform, anyway.
—SA
Philippe Mori 8-May-13 23:11pm
   
By the way, usually you are not able to use 100% of the memory theorically available because of memory fragmentation and miscellaneous overhead like memory alignment and "hidden" memory or grow factor for some container.

The allocation limit is defined by two factors: instruction-set architecture of the processor used (should be supported by the adequate Windows version), and available physical memory. On top of it, the allocation is limited by the current level of memory utilization. Yes, there is a 2GB limit, but only for 32-bit versions. As you can see, 32-bit flat address space limit the number of addressable bytes by 4Gb, but, according to Windows documentation, only 2Gb or 3Gb (tunable) is reserved by OS for applications.

Apparently, this 4Gb-based limitations are not applicable to 64-bit instruction-set architectures, so, in practice, these days, addressable space is limited by the physically available RAM and OS.

For further detail, please see: http://msdn.microsoft.com/en-us/library/windows/desktop/aa366778%28v=vs.85%29.aspx[^].

See also: http://en.wikipedia.org/wiki/Instruction_set[^].

[EDIT]

I just noticed that you did not tag your OS as Windows or anything else. I just assumed it was about Windows, because you mentioned the familiar 2Gb barrier.

Please see my comment to the question; always tag your platform. For other OS, please see appropriate documentation.

I also forgot to mention that, next to the instruction-set architecture of the CPU, the memory is apparently limited by the design of the motherboard. In some cases (especially in the past models), even if the number of slots was enough for some maximum amount of memory, not all combinations of memory modules works at full capacity or even recognized. Before you buy memory, always consult the motherboard documentation.

—SA
   
v4
Comments
dj4400 9-May-13 3:23am
   
You are right i forgot to mention that i work under win 7 64 Bit.
I have A 64 Bit machine But My App loads A 32 Bit Dll so I Assumed That I Have To Compile Under 32 Bit.
How Do i tune to 3 Gb?
Thanks
   
On 64-bit Windows 7/8, this is already full 4G (except Windows 7 Starter). Please see the same for other versions in the same document.
See also:
http://en.wikipedia.org/wiki/WoW64

—SA
CPallini 9-May-13 3:59am
   
5.
   
Thank you, Carlo.
—SA
Malli_S 9-May-13 9:29am
   
5ed.
   
Thank you, Malli.
—SA
Changing a flag in the project properties.
Go To Properties-»linker-»system and Set
The Enable Large addresses To Support
addresses Larger Than 2Gb
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900