PDA

View Full Version : Memory alocation in windows


Hero
June 27th, 2007, 01:59
Hi all
In my small program,I forced to write several threads(5 of them) and heavily process some data and APIs in it.
One of these important APIs is "GlobalAlloc" and "GlobalFree",it means that I forced to allocated some memory at start of a loop in my thread using GlobalAlloc(with GPTR flag) and free it using GlobalFree at the and of loop,and this happens for all threads.

Here is my question:
Is there any guarantee that my allocated memory in a thread has no overlapping with allocated memory in other threads?

Regards

fr33ke
June 27th, 2007, 03:10
GlobalAlloc calls RtlLockHeap which in turn calls RtlEnterCriticalSection*. I suppose this is similar to the wine source**. So I think GlobalAlloc is thread safe. Just like a single thread there is no chance to get the same memory twice.

*http://www.openrce.org/reference_library/win32_call_chains/2000SP4/KERNEL32/GlobalAlloc
**http://source.winehq.org/source/dlls/ntdll/heap.c#L1470