The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: cman on June 01, 2010, 07:41:49 PM

Title: Memory Allocation
Post by: cman on June 01, 2010, 07:41:49 PM
Whats the difference in GMEM_FIXED and GMEM_MOVEABLE options for a allocation API like GlobalAlloc ? What is the best option to use when building a dynamic data structure ( like a linked list , etc. ) . Thanks for any information.
Title: Re: Memory Allocation
Post by: redskull on June 01, 2010, 08:06:49 PM
Nothing, at least not anymore.  It's  a throwback from 16-bit Windows, when there were both Global and Local heaps, and when memory could be coalesced to conserve memory.

-r

EDIT - while *internally* there is no difference, using the 'moveable' option requires you to use the lock function to get a pointer from a handle, instead of the pointer directly.  But again, all this is for compatibility with 16-bit Windows, so you are better off using the heap.
Title: Re: Memory Allocation
Post by: hutch-- on June 02, 2010, 01:59:05 AM
Apart from compatibility with the clipboard and a few other capacities, the GMEM_MOVABLE option is obselete where the GMEM_FIXED is still a viablle method of allocating a fixed block of memory. A quirk of how the 32 bit version of the GlobalAlloc() family of memory allocation functions work is that if you use GlobalReAlloc() you have to set the movable flag but it reallocates the pointer returned from the originbal GlobalAlloc() call and the new address is also fixed memory.

Main virtue of GlobalAlloc() with the GMEM_FIXED is its fast, simple and reliable.