Thread: memory

  1. #1
    ‡ †hë Ö†hÈr 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
    ‡ †hë Ö†hÈr 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, 02:14 AM
  2. Question regarding Memory Leak
    By clegs in forum C++ Programming
    Replies: 29
    Last Post: 12-07-2007, 01:57 AM
  3. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  4. Shared Memory - shmget questions
    By hendler in forum C Programming
    Replies: 1
    Last Post: 11-29-2005, 02: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-15-2001, 12:37 AM