News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Memory Allocation

Started by cman, June 01, 2010, 07:41:49 PM

Previous topic - Next topic

cman

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.

redskull

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.
Strange women, lying in ponds, distributing swords, is no basis for a system of government

hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php