Say, for instance, I have 16GB of memory and am doing a very large amount of dynamic memory allocation in C (just for testing, nothing in particular). How can I determine how large the heap will be able to grow to, to accommodate my calloc
's?
Asked
Active
Viewed 382 times
1
-
Why do you want to? It is hadly possible to do that. Just allocate whatever memory you need and handle faults. – too honest for this site Jul 22 '16 at 20:23
-
I'm just curious about approximately what % of total RAM is available for the heap on average and thought I could look at my own system. I was thinking in the future if I'm working on something with a low amount of RAM it would be useful to have an idea of how much the heap could use off the top of my head. – Austin Jul 22 '16 at 20:23
-
You are on a multiprocessing, multi-CPU system with hundeds of concurrent processes. Well, that question has been asked multiple times before. Do some research! – too honest for this site Jul 22 '16 at 20:25
-
I can't find a previous post that addresses it or a google link. Maybe I don't know what the proper search terms should be. – Austin Jul 22 '16 at 20:26
-
1Open the *"Launchpad"*, find the *"Activity Monitor"*, and click on the *"Memory"* button at the top of the window. At the bottom of the window, it will show the memory size, and the memory used. – user3386109 Jul 22 '16 at 20:30
-
can the heap use all the way up to (memory size - memory used) or less than that? – Austin Jul 22 '16 at 20:32
-
2google: "stack overflow determine size of heap" -> 3rd result: http://stackoverflow.com/questions/12687274/size-of-stack-and-heap-memory (already a dup) - Are people really not even able to google anymore? – too honest for this site Jul 22 '16 at 20:34
-
2Bear in mind that items in the process address space, like the stack and the heap, are part of *virtual memory*. They might reside in RAM, they might not. On a lightly loaded system it might all be in RAM, on an over subscribed system that is page-faulting like mad then only the minimum working set might be in RAM. RAM (as opposed to virtual memory) usage is very difficult to predict. – cdarke Jul 22 '16 at 20:40
-
Due to virtual memory, you can use more than (memory size - memory used), but when you do that, the program slows down, and the hard drive heats up (gets used a lot). I would leave a margin of at least 500MB to avoid thrashing the hard drive. – user3386109 Jul 22 '16 at 20:43
-
Why not just use the `heap` utility? – l'L'l Jul 22 '16 at 20:46