Hello everybody,

I'm using global memory functions: GlobalAlloc, GlobalLock, GlobalUnlock, GlobalFree. I get no errors with any of these functions and everything seems to work well. By chance I was stepping through the code with VC debugger and I noticed that calling GlobalFree always wrote what looks like to double words: 78011300 78011300 at the beginning of the allocated memory area. Does anybody know what's happening here, or why.

Any ideas appreciated,
best regards,

czDrillard
Posted on 2005-01-23 12:29:18 by czDrillard
It is probably updating heap control structures.
And btw, why are you using Global* when there's Heap*?
Posted on 2005-01-23 13:02:40 by f0dder
You say that everything works well. However, this is not as mysterious as it seems. Remember that they were designed to do just that. If Windows didn't work, it would not have been as popular as it is today. Therefore, the designers decided in favour of a working system. And history has shown that this decision was right.
Other systems, who follow the principle of just barely working, sometimes, are not in widespread use.
Posted on 2005-01-23 14:24:29 by Sephiroth3
Thanks for replies,

f0dder, I remember your posts since I have been a member of this board and you always were strong advocate for heap functions. Why am I still using Global* I'm going to blame it on Iczelion's tutorials: I was making the switch from c programming to 32 bit assembler and the first memory functions I used were global* Just never got with the 21st century flow and made the switch :-D

Sephiroth3, good point. I won't fix it if it's not broke.

best regards,

czDrillard
Posted on 2005-01-24 09:29:37 by czDrillard
Sorry for my ignorance, but I as well am still learning Win32 ASM (Also from Iczelion at the moment). f0dder, you would be able to give a brief explanation as to why Heap* is better than Global*? Just curious and any information is greatly appreciated :)
Posted on 2005-01-24 09:37:18 by DaRetard
Memory management is a very interesting subject!

I also used to use the Global* functions until I read about memory management on MSDN:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/memory/base/global_and_local_functions.asp
(see the links on that page for even more fun stuff)

They always have some interesting read, if you want to make your proggies run the way Windows wants them to. Though often it's very hard to find what you're looking for.

good luck and good night!
Posted on 2005-01-24 17:55:48 by enodev
Ahhh I see. So it's basically that "global and local functions are slower than other memory management functions and do not provide as many features", which is why "new applications should use the heap functions". Gotcha; thanks for the link :)
Posted on 2005-01-24 18:24:38 by DaRetard
DaRetard, also you might want to read f0dder's article on this subject -
http://f0dder.schwump.net/memalloc.htm

And on something, related to the topic - on win98se , when you use HeapAlloc, at dword ptr is the size of this buffer, with the highest two bits set - marking whether it's a free chunk or not.
On win2k now I tried the same stuff, saw that there are at least 2 (maybe even 4) dwords before the allocated memory, that contain encoded info for the buffer. This is the way , I guess, for the Heap object to manage its data. And when you need to grow the heap, extra pages are appended to its end - it doesn't matter actually where that memory is physically :-D .
That location seems interesting, so I tried overwriting it, expecting a GPF or at least a warning when freeing the allocated memory - but to no avail . Probably the heap object expects special encodings in different ranges of buffer sizes. Haven't toyed enough with this yet :P
Posted on 2005-01-24 20:59:54 by Ultrano