memory

This is a discussion on memory within the Windows Programming forums, part of the Platform Specific Boards category; GlobalAlloc(UINT uFlags, SIZE_T dwBytes); HeapAlloc(HANDLE hHeap, DWORD dwFlags, SIZE_T dwBytes); LocalAlloc(UINT uFlags, SIZE_T uBytes); new why are there so many ...

  1. #1
    Nor
    Nor is offline
    h ֆhr s Nor's Avatar
    Join Date
    Nov 2001
    Posts
    299

    memory

    GlobalAlloc(UINT uFlags, SIZE_T dwBytes);
    HeapAlloc(HANDLE hHeap, DWORD dwFlags, SIZE_T dwBytes);
    LocalAlloc(UINT uFlags, SIZE_T uBytes);
    new

    why are there so many ways to allocate memory to your programs???
    is there anything wrong with simply using new?
    Try to help all less knowledgeable than yourself, within
    the limits provided by time, complexity and tolerance.
    - Nor

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    GlobalAlloc and co. are old and slow. You should use the Heap Functions now.

    As for calling new or malloc. Well it's like naming your variables FLOAT instead of float. FLOAT is the Win32 typedef for float's. This way your project is a lot more flexible. I'm sure someone else can elaborate more, however, I am late for work.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    245
    There's nothing wrong with using 'new', but the other functions do give more flexibility. For example, with LocalAlloc, you can state whether you want the memory fixed or movable. The preferred functions are the ones like HeapCreate, HeapAlloc, etc, but you'll most likely find that your compiler uses these behind your back when you use things like "new" anyway, so unless you have special requirements, just stick to the standard c/c++ calls.

  4. #4
    Nor
    Nor is offline
    h ֆhr s Nor's Avatar
    Join Date
    Nov 2001
    Posts
    299
    thx
    Try to help all less knowledgeable than yourself, within
    the limits provided by time, complexity and tolerance.
    - Nor

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 01-13-2008, 01:14 AM
  2. Question regarding Memory Leak
    By clegs in forum C++ Programming
    Replies: 29
    Last Post: 12-07-2007, 12:57 AM
  3. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  4. Shared Memory - shmget questions
    By hendler in forum C Programming
    Replies: 1
    Last Post: 11-29-2005, 01:15 AM
  5. What's the best memory (RAM) type?
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 12-14-2001, 11:37 PM

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