I need to know how you do memory allocation. Is anyone here know the different beetween WinXP SP2 with WinXP Sp1?
Posted on 2005-08-11 07:19:29 by realvampire
HeapAlloc for generic allocations, VirtualAlloc for huge allocations, VirtualAlloc + custom sub-allocation for specific needs, and GlobalAlloc where required (clipboard API, CreateStreamOnHGlobal, ...)

Differences for XP SP2? If you need to dynamically generate code, you'll need to use VirtualAlloc and specify the PAGE_EXECUTE flag (ie, something like PAGE_EXECUTE_READWRITE, then use VirtualProtect to remove the write access once you're done constructing the code).

If you don't deal with dynamic code construction, nothing to worry about.
Posted on 2005-08-11 08:07:45 by f0dder
... and LocalAlloc for unecessarily allocations  :P  :P  :D
Posted on 2005-08-11 10:27:45 by Criminal2
hitchickr said winXP SP2 have a protect for memory allocation. Have you try to allocating a memory on WinXP SP2?
Also if I want to allocate 3 MB what function I must use? Is GlobalAlloc still able to?
Posted on 2005-08-11 21:12:21 by realvampire
The additional protection that XP SP2 adds is, as I've already said, related to running code. If you don't generate code on-the-fly, you don't need to worry about it - see my previous post.

Stick to HeapAlloc for generic allocation. GlobalAlloc is deprecated (see PlatformSDK).
Posted on 2005-08-14 08:11:40 by f0dder

Have a look at this thread as it has some benchmarking written by chep that dispells much of the folklore aout how fast memory allocation is.



hutch at movsd dot com
Posted on 2005-08-14 09:36:10 by hutch--
By the way, MSDN advices against using HEAP_NO_SERIALIZE for the default process heap:

This value should not be specified when accessing the process heap. The system may create additional threads within the application's process, such as a CTRL+C handler, that simultaneously access the process heap.

...so if you want to be safe, only use this value for heaps you have created yourself.

If you really want performance, construct your own memory allocator around VirtualAlloc (possibly with smart handling of MEM_RESERVE + MEM_COMMIT) - will take some work to make it robust & better than HeapAlloc, but it can be worth it.
Posted on 2005-08-16 10:31:46 by f0dder