PC RAM and process address space


 
Thread Tools Search this Thread
Top Forums Programming PC RAM and process address space
# 1  
Old 11-30-2011
PC RAM and process address space

Suppose I have 3 gb of ram and 250 gb hard disk in my pc.
Now I wrote a simple C program having only one statement malloc() to allocate 4 gb of memory as 32 bit os can address 4gb address space then will the malloc succeed?
If yes then how it will get extra 1 gb of memory?
Does the process gets memory only from RAM or also from harddisk?
# 2  
Old 11-30-2011
malloc cannot succesfully make a request for memory that exceeds virutal memory. virtual memory = RAM + swap.

So the answer is no.

You also have to factor in the memory used by resident programs, and memory used by the OS itself.
This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 11-30-2011
A malloc() for 4 gigs of RAM on 32-bit probably would not succeed. There's a limit of 4 gigabytes per process in 32-bit and the process must have some memory already, for stack space, C libraries, and so forth. It'd never find room for an entire 4 gigabytes left over.

How about allocating 2 gigs of RAM on a 32-bit system with 1 gig of memory? That's a lot more possible.

The answer, actually, depends on your operating system.

On a Linux system, it wouldn't allocate any memory or swap space at all. It'd just mark down that the process has 2 gigs of RAM at this address range. No pages would be allocated until the process used it.

On most other UNIX systems, you need to use exactly as much swap as memory that's being allocated, with no exceptions. To allocate 2 gigs of RAM you need 2 free gigs of swap, period. It's possible to have more swap than RAM, so you can allocate more memory than your system has and the system will use swap to make up the difference.
This User Gave Thanks to Corona688 For This Post:
# 4  
Old 12-01-2011
Did you even try to compile it...because if you gave the right switches for a 32-bit compilation it will give a runtime error and if it didnt that's because the default compilation on linux is 64-bit meaning the malloc will succeed.
This User Gave Thanks to shamrock For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

RAM Utilization per process

Hello All, My Server RAM utilization is exceeding 90% and i would like to idnetify the per process RAM utilization.. We are using Solaris 10 10/9 OS release... Is there any way achieve this ??? Definitely not interested in any of the third party tool but some Solaris command... ... (5 Replies)
Discussion started by: EmbedUX
5 Replies

2. Programming

How to get address space size that a process is allowed to use

Hi All, From C++, I just want to find the address space size that a process is allowed to use. For ex, in 32 bit OS the allowed address space is 4GB and in 64 bit OS I guess this is 16GB or more. I jsut want to find it in my C++ project. Is there any API calls that gives me such information.... (2 Replies)
Discussion started by: Sendil Kumar
2 Replies

3. Solaris

How much portion of RAM is allocated to Swap space?

How swap is getting 12GB as its size as per the below output: Filesystem size used avail capacity Mounted on /dev/md/dsk/d0 7.9G 2.1G 5.7G 27% / /devices 0K 0K 0K 0% /devices ctfs 0K 0K 0K 0% /system/contract proc 0K 0K 0K 0% /proc mnttab 0K 0K 0K 0% /etc/mnttab swap 12G 1.2M 12G 1%... (3 Replies)
Discussion started by: ramnagaraj
3 Replies

4. Filesystems, Disks and Memory

Disk space and RAM status in UNIX

I have an application which is running under AIX, HP UNIX, SCO, and LINUX(redhat and SuSE). and its dealing with some bulk amount of file handling, and some of my boxes are not very good in terms of resources like memory and disk space. so i wanted to know the statistics of each of my boxes. Like... (2 Replies)
Discussion started by: renjithram
2 Replies

5. UNIX for Advanced & Expert Users

Can kernel process access user address space ?

Can kernel process access user address space ? (2 Replies)
Discussion started by: subhotech
2 Replies

6. Programming

Find Virtual address space size for process

Hi, I am looking to work on unix systems which include (hp-ux, ibm aix, solaris and linux). I want to get the total virtual address space of a process, the used virtual memory i am able to get without any problem. I have tried using getrlimit and getrlimit64, but that gives only ... (4 Replies)
Discussion started by: uiqbal
4 Replies

7. UNIX for Dummies Questions & Answers

How to find out how much RAM that process is using

H:confused:ow to find out how much RAM that process is using. like how much memory java.exe process is consuming (3 Replies)
Discussion started by: redlotus72
3 Replies

8. Solaris

RAM Physical Memory usage by each Process.

Hi All, I am trying to find the physical memory usage by each process/users. Can you please let me know how to get the memory usage?. Thanks, bsraj. (12 Replies)
Discussion started by: bsrajirs
12 Replies

9. UNIX for Dummies Questions & Answers

Ram space

Hi, I am new to Unix and I need to know how to find out how much Ram I have on my server. I have Sun Solaris operating system with Sun Ulta 10 cpu. Could you please let me know the command to find the current Ram I have? Thank you. (1 Reply)
Discussion started by: hollowayt
1 Replies

10. UNIX for Dummies Questions & Answers

How to find the size of Process Address space.

Hello, Please help me to know, How to find out the how much amount of process addres space is required/is used for/by a process. Tnx & Regards Vishwa. (1 Reply)
Discussion started by: S.Vishwanath
1 Replies
Login or Register to Ask a Question