News:

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

Heap allocation

Started by pro3carp3, March 31, 2005, 02:09:27 PM

Previous topic - Next topic

pro3carp3

What is the difference, practically speaking, between using Malloc, HeapAlloc, & VirtualAlloc (advantages/disadvantages)?  Also, is it better to use the program's heap or to initiate a private heap?  It seems HeapAlloc has the potential for fragmentation issues, & VirtualAlloc may be slow due to garbage collection.  I need to allocate memory blocks anywhere from a 4 bytes to hundreds of thousands of bytes with the lengths of the arrays changing as the program runs.  Any suggestions?  Thanks.
LGC

roticv


hutch--

pro3carp3,

With variable size allocations done of the fly from small to large, try the OLE string memory allocation functions. They are used in the two macros in MASM32 alloc$() and free$.




            include \MASM32\include\oleaut32.inc
            includelib \MASM32\LIB\oleaut32.lib

  ; -----------------------

      alloc$ MACRO ln
        invoke SysAllocStringByteLen,0,ln
        mov BYTE PTR [eax], 0
        EXITM <eax>
      ENDM

      free$ MACRO strhandle
        invoke SysFreeString,strhandle
      ENDM
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php