The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: pro3carp3 on March 31, 2005, 02:09:27 PM

Title: Heap allocation
Post by: pro3carp3 on March 31, 2005, 02:09:27 PM
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.
Title: Re: Heap allocation
Post by: roticv on March 31, 2005, 02:37:35 PM
Take a look at the following article: http://f0dder.schwump.net/memalloc.htm
Title: Re: Heap allocation
Post by: hutch-- on March 31, 2005, 02:53:27 PM
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