malloc limitations
-
We know that in a 32 bit system a 4 gb memory gets allocated to a process. So how much maximum memory can be allocated using a malloc function call?
-
We know that in a 32 bit system a 4 gb memory gets allocated to a process. So how much maximum memory can be allocated using a malloc function call?
-
Thanks Niklas for the inputs If suppose I am using a 32 bit windows or linux OS then what will be the limit?
-
We know that in a 32 bit system a 4 gb memory gets allocated to a process. So how much maximum memory can be allocated using a malloc function call?
rupeshkp728 wrote:
We know that in a 32 bit system a 4 gb memory gets allocated to a process.
It's 2GB unless the /3GB startup switch is used.
rupeshkp728 wrote:
So how much maximum memory can be allocated using a malloc function call?
Since it has to be contiguous, no more than 2GB, but realistically it will be less.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
-
rupeshkp728 wrote:
We know that in a 32 bit system a 4 gb memory gets allocated to a process.
It's 2GB unless the /3GB startup switch is used.
rupeshkp728 wrote:
So how much maximum memory can be allocated using a malloc function call?
Since it has to be contiguous, no more than 2GB, but realistically it will be less.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
Thanks David for the solution
-
Thanks Niklas for the inputs If suppose I am using a 32 bit windows or linux OS then what will be the limit?
Again it depends on the OS. In window, usually a process can take only 2GB of memory( User mode ), the remaining 2GB is reserved for Kernal mode. Again among this 2GB, some memory will be already taken by process, for loading exe, dll, heap, stack etc. So technically, the maximum about of memory that you can specify in malloc is always less than 2GB and the excat value depends on various factors I mentioned above. I dont know about Linux :(
nave [My Articles] [My Blog]
-
We know that in a 32 bit system a 4 gb memory gets allocated to a process. So how much maximum memory can be allocated using a malloc function call?
That's a bit like asking "how long is a piece of string?" Here's why... - Every process is given it's own address space to run in. Depending on where the OS and compiler conspire to load your code will determine the largest lump of memory you can allocate - The OS may allocated loads of other guff which will restrict where the compiler can stick it's heap - The OS may have extra overheads managing it's heap (e.g. Windows having different heaps for different size ranges of allocation) - How malloc is implemented on top of the underlying OS can also mess things up - The computer may not have enough disk space or memory to service your request So to find out how much you can allocate try it! Do a malloc for INT_MAX bytes and if that fails divide the size by 2 and try again. You can use something a bit more sophisticated but you really need to try it on a particular system with a given compiler and load to see what happens. Cheers, Ash
-
That's a bit like asking "how long is a piece of string?" Here's why... - Every process is given it's own address space to run in. Depending on where the OS and compiler conspire to load your code will determine the largest lump of memory you can allocate - The OS may allocated loads of other guff which will restrict where the compiler can stick it's heap - The OS may have extra overheads managing it's heap (e.g. Windows having different heaps for different size ranges of allocation) - How malloc is implemented on top of the underlying OS can also mess things up - The computer may not have enough disk space or memory to service your request So to find out how much you can allocate try it! Do a malloc for INT_MAX bytes and if that fails divide the size by 2 and try again. You can use something a bit more sophisticated but you really need to try it on a particular system with a given compiler and load to see what happens. Cheers, Ash
Thanks Ash for the reply. I tried malloc with INT_MAX and it indeed fails and with your way we can find out how much exactly the memory can be allocated.