News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

HeapAlloc() test.

Started by hutch--, September 22, 2016, 01:04:24 PM

Previous topic - Next topic

hutch--

I have found a problem with GlobalReAlloc and while I have written a work around, this is a test of the HeapAlloc() family of functions. If you are using one of the other assemblers you may need to change the console output with something like StdOut(). With the linker option /LARGEADDRESSAWARE the functions have been tested on very large memory allocations, 16 and 32 gig and they work fine. This of course depends on the amount of available memory on the machine.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \masm32\include64\masm64rt.inc

    .data?
      pHeap dq ?

    .code

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

entry_point proc

    LOCAL pMem :QWORD
    LOCAL pCnt :QWORD

    mov pHeap, rv(GetProcessHeap)
    conout str$(pHeap)," GetProcessHeap",lf

    mov pMem, rv(HeapAlloc,pHeap,HEAP_ZERO_MEMORY,1024*1024*1024)
    conout str$(pMem)," HeapAlloc",lf

    mov pCnt, rv(HeapSize,pHeap,0,pMem)
    conout str$(pCnt)," HeapSize",lf

    mov pMem, rv(HeapReAlloc,pHeap,HEAP_ZERO_MEMORY,pMem,1024*1024*512)
    conout str$(pMem)," HeapReAlloc",lf

    mov pCnt, rv(HeapSize,pHeap,0,pMem)
    conout str$(pCnt)," HeapSize",lf

    fn HeapFree,pHeap,0,pMem
    conout str$(rax)," HeapFree",lf

    waitkey

    invoke ExitProcess,0

    ret

entry_point endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    end