Re: Is malloc allocating memory on the virtual memory space ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Guerra-Salcedo, Cesar M wrote:
> Hello,
>
>
>
> I have been trying to understand some performance and limitations issues of a program written in C for
>
> Hp-UX 11. I am using Malloc to allocate memory for two arrays (huge arrays). If I try to go beyond 1G
>
> the program crashes. when I look at the stats using glance RSS and VSS look pretty much the same (RSS 1047364 and VSS 1048808) my understanding (I guess wrong) was that Malloc allocated on Virtual memory.
>
> Is there a way in C to allocate on VM only so the process address space (1G) is not touched (or barely touched). Thanks a lot for your help
>   

Process memory is virtual memory, well normally.  The usual way heap
allocations goes is that the kernel will create page table entries for
your allocated memory, but not actually [or always] map it to physical
memory until it's touched (e.g. creates a page fault).

The program shouldn't crash just because you malloc beyond 1G, more
likely it's returning NULL and you're dereferencing the pointer.  Could
be you have a ulimit in place, or a platform specific hard limit.  At
anyrate it has to map the memory into your process'es address space. 
For example, if you have a hard limit of 1GB of process memory, and your
code is 512MB, then you can only allocate 512MB of data before running
out of address space.

Well strictly speaking this all depends on the platform... but usually
code/data are mapped to the same address space, which allows for things
like self-modifying code and the like. 

Tom

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux