News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Heap problem

Started by shankle, September 13, 2014, 12:48:57 AM

Previous topic - Next topic

shankle

                             9-12-2014

This is a 64-bit program
Running Windows 7 pro 64-bit and GoAsm
memory of the puter is 6G

This code is failing way before 1,600,000
In HeapCreate the 3rd parameter is set to zero and
what I see in the API Doc is that this will allocate
more memory as it is growable.
The actual # of bytes read by ReadFile is in the neighborhood
of 125000. Anything more causes failure.
No Heap errors are generated.

The file that is being read in is a tad less than 1,600,000 bytes.

BytesRead dq    0
FileSize     dq    0
HeapH     dq    0  ; heap handle
hFile        dq    0
PtrMem    dq    0
FileByte  . db    0

    invoke GetFileSize, [hFile],NULL
    mov [FileSize],rax       
    invoke HeapCreate, HEAP_GENERATE_EXCEPTIONS,1600000,0
    mov [HeapH],rax
    invoke HeapAlloc, [HeapH],HEAP_GENERATE_EXCEPTIONS,1600000
    mov [PtrMem],rax
   
    mov rcx,[PtrMem]
    xor rsi,rsi
.n7   
   cmp rsi,[FileSize]
    jge >>.n9
    invoke ReadFile, [hFile],addr FileByte,1,addr BytesRead,NULL
   
    mov al,B[FileByte]
    mov B[rcx+rsi],al   ; builds data from readfile to memory
    inc rsi
    jmp <.n7
.n9
   
Help would be most appreciated.   


qWord

Quote from: shankle on September 13, 2014, 12:48:57 AM
BytesRead dq    0
HeapH     dq    0  ; heap handle
hFile     dq    0
PtrMem    dq    0
FileByte  db    0

   invoke HeapCreate, HEAP_GENERATE_EXCEPTIONS,1600000,0
   mov [HeapH],rax
   invoke HeapAlloc, [HeapH],HEAP_GENERATE_EXCEPTIONS,0 ; <=========== dwBytes = 0 ???
    mov [PtrMem],rax
   
    invoke ReadFile, [hFile],addr FileByte,1,addr BytesRead,NULL  ; where is PtrMem used?
MREAL macros - when you need floating point arithmetic while assembling!

shankle

See above revamped code. Still does not work.

wjr

Your [PtrMem] value in rcx will get changed with the call to ReadFile. Try using rbx or rdi instead if available.

qWord

That loop is crap! Make one call to ReadFile with nNumberOfBytesToRead = FileSize and then process the read file-data.
MREAL macros - when you need floating point arithmetic while assembling!

shankle

Problem solved.
Thread closed