size of heap memory

Jul 6, 2010 at 7:55pm
Hi,
I did googling before pasting this question but did not find any suitable information.anyone have any idea

1.Where heap memory allocated (is it RAM or RAM + harddisk)

As I came to know when stack and heap allocated memory in RAM than why we need

heap memory as we face memory overflow in both memory.

2 . how could we determine available heap memory.

Please provide me input
Jul 6, 2010 at 8:10pm
1. It's in the RAM, unless it's swapped out on disk. Same for the stack.
The stack is limited to 2 MB by default and it is... well, a stack, i.e. a LIFO structure. The heap is much larger and allows arbitrary allocations and deallocations.
2. Depends on the OS.
Jul 6, 2010 at 8:32pm
Also, without heap allocation it would be impossible for objects to outlive the functions that created them.
Jul 6, 2010 at 9:44pm
(Any size limitation on a stack is arbitrarily imposed by the operating system).
Jul 8, 2010 at 4:44pm
you mean we do not size limitation on the heap.
Jul 8, 2010 at 9:50pm
The heap consists of RAM + Swap Space. Swap Space is hard drive space reserved for use as RAM if you run low on physical RAM.

Obviously you want to try to avoid using swap space as much as possible since waiting for the hard drive to seek and fetch your memory is extremely slow compared to physical RAM.

Stack space is a small amount of RAM set aside for your program to pass arguments and so forth so you should not think of this RAM as a place to store your data.

Stack grows from the top of your memory downward, and the heap grows from bottom to the top.

Here's a simplified diagram to help you visualize:

--- Top of RAM
|
|- Reserved Stack Space
|- Available RAM ---> Swap Space
|- Heap Memory
|- Reserved System Memory
|
--- Bottom of RAM

As the heap (the RAM you program is using) grows upward it uses more and more available RAM until these is no more left, then starts using swap space.
Last edited on Jul 9, 2010 at 1:37am
Jul 9, 2010 at 12:28am
What you're calling virtual memory is known everywhere as just swap space. Virtual memory is something different.
http://en.wikipedia.org/wiki/Virtual_memory

Obviously you want to try to avoid using VM or swap space as much as possible
Which is impossible unless you know in advance what the VMM will do and how much physical memory is available.
Jul 9, 2010 at 1:44am
I repaired my mistake about VM in my other post.


Obviously you want to try to avoid using VM or swap space as much as possible

Which is impossible unless you know in advance what the VMM will do and how much physical memory is available.

Granted. I only meant that you would try to do everything you can to keep your program as lean as possible to minimize the likelihood.
Topic archived. No new replies allowed.