I need to know how you do memory allocation. Is anyone here know the different beetween WinXP SP2 with WinXP Sp1?
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.
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.
... and LocalAlloc for unecessarily allocations :P :P :D
Fodder:
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?
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?
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).
Stick to HeapAlloc for generic allocation. GlobalAlloc is deprecated (see PlatformSDK).
farabi,
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.
http://www.masmforum.com/simple/index.php?topic=1943.0
Regards,
hutch at movsd dot com
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.
http://www.masmforum.com/simple/index.php?topic=1943.0
Regards,
hutch at movsd dot com
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.
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.