views:

68

answers:

4

i have following question i have RAM 2.5 GB in my computer what i want is if it is possible that in case of allocate totally memory to some process or for example char * buffer=malloc(2.4GB) , no more process ( google chrome, microsoft games in computer..etc) can run?

A: 

Computer works with virtual memory, this has no relation to a real size of RAM.

Pmod
+1  A: 

Probably not. First, your operating system will have protections ie, malloc eventually becomes a system call in your OS so it will fail instead of killing everything. Second, because of virtual memory you can have more allocated memory than RAM so that even if your OS were to let you allocate 2.5 gigs it will still be able to function and run processes.

cohensh
A: 

In a OS like Windows where each process gets a 4GB (assuming 32 bit OS) virtual address space, it doesn't matter how much RAM you are having. In such a case malloc(2.4GB) will surely fail as the user address space is limited to 2GB only. Even allocating 2GB will most probably fail as the system has to allocate 2GB of continuos virtual address space for malloc. This much continous free memory is nearly impossible due to fragmentation.

Naveen
+1  A: 

While it is OS and compiler dependent, on Visual C++ under 32 bits windows, you will typically be unable to malloc more than 512MB at a time. This controlled by the preprocessor constant _HEAP_MAXREQ. For details of the approach I used to work around this limitatation, see the following thread If you go to 64 bits, this also ceases to be an issue, although you might end up using much more virtual memory than you would expect.

Shane MacLaughlin