Managing memory in Windows prior to Win32 involved a great deal of uncertainty 
about using the C run-time (CRT) library. With 
Win32 there should be little hesitation. The CRT library in Win32 is 
implemented in a manner similar to FIXED memory allocated 
via the local and global memory management functions. The CRT library is also 
implemented using the same default heap manager as 
the global and local memory management functions.

Subsequent memory allocations via malloc, GlobalAlloc, and LocalAlloc return 
pointers to memory allocated from the same heap. 
The heap manager does not divide its space among the CRT and global/local 
memory functions, and it does not maintain separate 
heaps for these functions. Instead, it treats them the same, promoting 
consistent behavior across the types of functions. As a 
result, you can now write code using the functions you're most comfortable 
with. And, if you're interested in portability, you 
can safely use the CRT functions exclusively for managing heap memory.

Summary and Recommendations

Heap memory management in Win32 is greatly improved over past versions of 
Windows. Instead of a systemwide global heap and 
application-specific local heaps, each application in Win32 has a default heap 
and as many dynamic heaps as the application 
wants to create. Both types of heaps can grow dynamically and use as much of 
the address space as they need to satisfy an 
allocation request.

The default heap provides all dynamic memory allocations for the C run-time 
library malloc functions as well as the global and 
local memory functions. The heap memory functions can also allocate from the 
default heap by using its handle, which they 
retrieve by calling the GetProcessHeap function.

The dynamic heap provides serialization to avoid conflict among multiple 
threads accessing the same heap. To support the 
management of multiple dynamic heaps, each heap is identified by a unique 
handle returned by the HeapCreate function.

Heaps do at least one thing well—they allocate smaller chunks of memory rather 
quickly. So whenever you are reluctant to create 
an automatic variable in a window procedure simply for an occasional LoadString 
buffer, why not use GlobalAlloc or LocalAlloc, 
malloc or HeapAlloc? Heaps are also very good at allocating storage for dynamic 
data structures. Dynamic heaps lend themselves 
particularly well to managing several distinct dynamic data structures in an 
application.

Finally, what is the cost of using a heap? Well, if you never use any MOVEABLE 
(including DISCARDABLE) memory, the cost is 
considerably lower, and MOVEABLE memory probably doesn't buy you much in a 
32-bit linear address space. Not to mention that at 8 
bytes per MOVEABLE memory handle, the system limits processes to 65,535 
handles. Each chunk of heap memory allocated in either 
the default heap or a dynamic heap is subject to a 16-byte granularity and is 
charged a 16-byte header. In total, then, 
allocating 1 byte of MOVEABLE memory costs 40 bytes (8 bytes for the handle 
table entry, 16 bytes for granularity, and 16 bytes 
for the header). Happy heaping

Best regards,
Miguel Angel marchuet


Patrick Mast escribió:
> Hello Miguel,
> 
>>> if you use -DHB_FM_WIN32_ALLOC then uses windows api memory manager
>>> in other case you was using -DHB_FM_STD_ALLOC.
> 
> When should we use -DHB_FM_WIN32_ALLOC and when -DHB_FM_STD_ALLOC?
> What is the advantage of using -DHB_FM_WIN32_ALLOC?
> 
> Patrick
> 
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> xHarbour-developers mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/xharbour-developers
> 
> __________ Información de ESET NOD32 Antivirus, versión de la base de firmas 
> de virus 3550 (20081023) __________
> 
> ESET NOD32 Antivirus ha comprobado este mensaje.
> http://www.eset.com
> 
> 
> 


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
xHarbour-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xharbour-developers

Reply via email to