I wrote a C program in Linux that mallocs memory, ran it in a loop, and TOP didn’t show any memory consumption.
then I’ve done something with that memory, and TOP did show memory consumption.
When I malloc, do I really “get memory”, or is there a “lazy” memory management, that only gives me the memory if/when I use it?
(There is also an option that TOP only know about memory consumption when I use it, so I’m not sure about this..)
Thanks
On Linux, malloc requests memory with sbrk() or mmap() – either way, your address space is expanded immediately, but Linux does not assign actual pages of physical memory until the first write to the page in question. You can see the address space expansion in the VIRT column, while the actual, physical memory usage in RES.