Iczelion's Tut 12 is about memory management and uses functions like GlobalAlloc, GlobalFree
But Microsoft says
The GlobalAlloc function allocates the specified number of bytes from the heap. Windows memory management does not provide a separate local heap and global heap.
Note: The global functions are slower than other memory management functions and do not provide as many features. Therefore, new applications should use the heap functions. However, the global functions are still used with DDE, the clipboard functions, and OLE data objects.
Why does he still teach GlobalAlloc instead for VirtualAlloc?
But Microsoft says
The GlobalAlloc function allocates the specified number of bytes from the heap. Windows memory management does not provide a separate local heap and global heap.
Note: The global functions are slower than other memory management functions and do not provide as many features. Therefore, new applications should use the heap functions. However, the global functions are still used with DDE, the clipboard functions, and OLE data objects.
Why does he still teach GlobalAlloc instead for VirtualAlloc?
VirtualAlloc has a lot of options (parameters), and allocates large blocks of memory.
If you are allocating and deallocating often, then you get better memory usage and speed using the other Alloc functions. The speed comes from reducing the number of context switches to and from system context. With VirtualAlloc, every time you allocate or deallocate memory, you get this performance drop from context switches.
I suggest using HeapAlloc instead of GlobalAlloc.
The primary differences are that you need to specify a heap handle, and there's no confusion about whether "locking" is required or not. When your program starts, there is already one heap handle available - use GetProcessHeap to get it.
If you are allocating and deallocating often, then you get better memory usage and speed using the other Alloc functions. The speed comes from reducing the number of context switches to and from system context. With VirtualAlloc, every time you allocate or deallocate memory, you get this performance drop from context switches.
I suggest using HeapAlloc instead of GlobalAlloc.
The primary differences are that you need to specify a heap handle, and there's no confusion about whether "locking" is required or not. When your program starts, there is already one heap handle available - use GetProcessHeap to get it.
I agree
Windows Me/98/95: The heap managers are designed for memory blocks smaller than four megabytes. If you expect your memory blocks to be larger than one or two megabytes, you can avoid significant performance degradation by using the VirtualAlloc or VirtualAllocEx function instead.
We can choose between Heap functions and Virtual functions but avoid Global (or Local) funcions
Windows Me/98/95: The heap managers are designed for memory blocks smaller than four megabytes. If you expect your memory blocks to be larger than one or two megabytes, you can avoid significant performance degradation by using the VirtualAlloc or VirtualAllocEx function instead.
We can choose between Heap functions and Virtual functions but avoid Global (or Local) funcions