Click here to Skip to main content
15,038,237 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

How much memory can we allocate with the help of malloc function
( malloc(sizeof(?)); )?

What is the max number in place of '?' mark?

I want to allocate 1 GB memory at a time, is this possible?

How does it depend on the system?
Posted
Updated 25-Aug-10 1:23am
v5
Comments
Dalek Dave 25-Aug-10 6:01am
   
Edited for Grammar and Syntax.
CPallini 25-Aug-10 6:26am
   
Edited Dave's comment for grammar and syntax. :-D
Removed the OP ridiculous 'it is urgent' sentence.
Aescleal 25-Aug-10 7:24am
   
Changed the tags to something more reasonable for the question

Hope this will help

Actually it depends on system.
   
Comments
patilvaibhavrao 25-Aug-10 6:10am
   
how it is depend on system
Nyarost 25-Aug-10 6:11am
   
Well I suppose there are different limits for Windows, Linux, BSD. Also it depends on system architecture: i386, amd64, ia64 and so on. Formula on Wikipedia says The maximum value is 2CHAR_BIT*sizeof(size_t) - 1, or the constant SIZE_MAX in the C99 standard. I assume you should check this constant.
4 bytes if you use an integer argument, 8 if you use a double.

Operator sizeof will return the size of the operand.

malloc(sizeof(675468)) => malloc(4), etc

Assuming 32 bit environment.
   
In addition to the other replies: if you have to allocate 1GB of memory, it is likely that you have so design issues. Why do you need to allocate that much memory at once ? What are you going to do with it ?
   

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