News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Memory allocation

Started by Farabi, August 11, 2005, 12:13:30 PM

Previous topic - Next topic

Farabi

How you do memory allocation. And what is the different beetween WinXP SP1 with the SP2 system?
Can you solve why I always made my software crashed on WinXP SP2 system.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

hitchhikr

Sp2 have a some memory protection against bad coders, paste some of your crashing code (and don't forget the part where you allocate the memory).

Farabi

Quote from: hitchhikr on August 11, 2005, 12:47:55 PM
Sp2 have a some memory protection against bad coders, paste some of your crashing code (and don't forget the part where you allocate the memory).

What is the criteria of bad memory allocation coder? I dont know which part is invalid.

here is the code

invoke GlobalAlloc,GMEM_ZEROINIT or GMEM_FIXED,1024*16
mov temp_memory,eax
invoke LocalAlloc,LMEM_ZEROINIT or GMEM_FIXED,16+12
mov v_tab,eax
; You can remove this
invoke LocalAlloc,LMEM_ZEROINIT or GMEM_FIXED,1024*16
mov shot_tmp,eax
invoke LocalAlloc,LMEM_ZEROINIT or GMEM_FIXED,1024*16
mov blow_tmp,eax
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

hutch--

Farabi,

The trick is with memory is to allocate what you need, use it and make sure you de-allocate it when you are finished. The old GlobalAlloc() is still viable but not the fastest for small allocations but fine for larger sizes.

Ther are many strategies for allocating memory but its a good idea to get the concept right first, then pick the one that is best suited for your task given that most of them will do simple tasks well.

It is good coding practice to make you allocation and de-allocation at the same time then code between the two pieces of code, this way you don't have to track down where to deallocate it after you have written your code.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Jeff

what are the differences between the Global/Local/Heap memory functions?  i read that Global and Local are pretty much identical nowadays.  would it be okay to use Heap memory functions?  Back in class, my instructor told us to use the Heap to allocate memory (only because we never brought up the others).  would there be any benefits/drawbacks for using one over another?

Tedd

GlobalAlloc and LocalAlloc are exactly the same function (they were slightly diff in windows 3, but now they're only kept for compatibility.)
Indirectly, they actually end up calling HeapAlloc, so you may as well just use HeapAlloc anyway :wink
No snowflake in an avalanche feels responsible.