Thread: Windows Memory Allocation :: C++

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348

    Windows Memory Allocation :: C++

    Hi.

    C++ offers the new operator to allocate a section of memory via heap.

    C offers the general malloc set of functions to allocate a section of memory via heap.

    Windows offers a series of functions. I would like to know what is the best memory allocation tool to use under windows. Again, I am a C++ programmer.

    I believe Windows has these memory related functions.

    GlobalAlloc()
    GlobaFree()
    HeapAlloc()
    HeapFree()
    LocalAlloc()
    LocalFree ()

    I would like to like under a C++ Windows program, what are the most appropriate memory allocation tool to use? Currently, I use C++ new operator to develop Windows winsock programs. However, I see programmers use GlobalAlloc almost all the time for Windows and Windows network programs. What is the advantage, if any, of GlobalAlloc that C++ new lacks, if any?

    Thanks,
    Kuphryn

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    operator new often calls malloc which in turn can call HeapAlloc...

    GlobalAlloc & LocalAlloc are remnants of Win16 and map to HeapAlloc anyway....Dont bother with them

    I prefer to use new (extensible, portable, typesafe ect....), but if I want any API representation, then HeapAlloc

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Okay. Thanks.

    A member posted an article from Microsoft MSDN with a lot of information about memory management in Win32.

    http://msdn.microsoft.com/library/de...sdn_heapmm.asp

    Kuphryn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Increasing memory allocation in function
    By Ramses800 in forum C Programming
    Replies: 3
    Last Post: 12-16-2008, 05:30 AM
  2. memory leak checker program? for windows
    By rahulsk1947 in forum C Programming
    Replies: 1
    Last Post: 11-12-2007, 07:20 AM
  3. Dynamic memory allocation.
    By HAssan in forum C Programming
    Replies: 3
    Last Post: 09-07-2006, 05:04 PM
  4. Memory Allocation :: C/C++
    By kuphryn in forum C++ Programming
    Replies: 4
    Last Post: 08-15-2002, 10:38 AM
  5. Is it necessary to write a specific memory manager ?
    By Morglum in forum Game Programming
    Replies: 18
    Last Post: 07-01-2002, 01:41 PM