+ Reply to Thread
Results 1 to 2 of 2

Thread: What is the difference between GlobalAlloc() or HeapAlloc()?

  1. #1

    What is the difference between GlobalAlloc() or HeapAlloc()?

    What is the difference between GlobalAlloc() or HeapAlloc()?

  2. #2
    Senior Member
    Join Date
    Feb 2012
    Posts
    109
    Starting with 32-bit Windows, GlobalAlloc is implemented as wrapper functions that call HeapAlloc using a handle to the process's default heap.
    Therefore, GlobalAlloc is having greater overhead than HeapAlloc.

    Because the different heap allocators provide distinctive functionality by using different mechanisms, you must free memory with the correct function.
    For example, memory allocated with HeapAlloc must be freed with HeapFree and not GlobalFree.
    Memory allocated with GlobalAlloc must be queried, validated, and released with the corresponding global function.

    GlobalAlloc/HeapAlloc is different than 'new'.

    You can use GlobalAlloc/HeapAlloc to share memory between two processes.
    You can pass memory pointer return by GlobalAlloc/HeapAlloc to another process compiled with another compiler. While this is not the case for 'new'!

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts