heap

This is a discussion on heap within the Windows Programming forums, part of the Platform Specific Boards category; Hello everyone, Two concepts about heap on Windows after reading MSDN document about heap functions. 1. Default heap. Each process ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    heap

    Hello everyone,


    Two concepts about heap on Windows after reading MSDN document about heap functions.

    1. Default heap. Each process has a default heap. But the default heap of different processes are different, right? Example, process 1 has default heap A and process 2 has default heap B, then A and B should be different heaps, right?

    2. Why a process needs to allocate private heap, any practical use?

    3. Are there any default global heap which different processes could share?


    thanks in advance,
    George

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    1. Yes, different applications have their own heaps. They are "personal" not "communal".

    2. I guess if you are writing something like a Java VM or a Lisp interpreter, you may want to have one heap that the VM uses, and one heap that the VM/interpreter uses for it's own internal purposes [that is, if you have for example a symbol table in the interpreter, that comes from the "interpreter heap", but a list of Lisp objects that belong to the lisp-code itself is allocated from the "lisp heap"]. There may be other situations too where an application could use multiple heaps - the reason generally would be to "split things up so that the different big blocks of functions don't interfere with each other". I expect you could have a separate heap for the GUI and "document" in a Word Processor for example.

    3. No, that would be shared memory, and you could of course build your own heap in some shared memory region, but the OS doesn't support this as such - and it would be much harder to manage, because you need to use locking to prevent two apps from "racing" each other when it comes to allocations, freeing and such.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    Quote Originally Posted by George2 View Post
    2. Why a process needs to allocate private heap, any practical use?
    Because there is a 2GB (3GB*) per process limit, but many motherboards support up to 4GB total system memory. By gving each process its own heap, windows can move the application around in memory and just change its segment registers without breaking the application. If multiple applications used the same heap, windows couldnt move the heap around, adn since a procvess can execute code on the heap, it woudl limit all processes to sharing the same 2GB and it woudl prevent windows from moving applications aroudn to prevent fragmentign the memory. So If I ran an aplication that uses 1GB adn then another that runs 1GB adn then one mor that runs 1GB then I shut the second one down, with a common heap I could not run a 2GB process because there woudlnt be a contiguous 2GB block of memory available. With per process heaps however, I can move teh 3rd program down simply by reaassigning its segment regeiers and fixing up the paging table. Remember, yoru program goes on the heap, global variables and allocated memory comes from the heap, local variables are created on the stack.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Heap Program Help
    By Rob4226 in forum C++ Programming
    Replies: 15
    Last Post: 05-02-2008, 01:23 AM
  2. Heap Work
    By AndyBomstad in forum C++ Programming
    Replies: 1
    Last Post: 05-16-2005, 12:09 PM
  3. Do you know...
    By davejigsaw in forum C++ Programming
    Replies: 1
    Last Post: 05-10-2005, 10:33 AM
  4. heap question
    By mackol in forum C Programming
    Replies: 1
    Last Post: 11-30-2002, 04:03 AM
  5. stach and heap.
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 01-26-2002, 08:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21