Author Topic: Heap problem  (Read 4050 times)

shankle

  • Member
  • ****
  • Posts: 868
Heap problem
« on: September 13, 2014, 12:48:57 AM »
                             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.   

« Last Edit: September 13, 2014, 01:50:05 AM by shankle »

qWord

  • Member
  • *****
  • Posts: 1475
  • The base type of a type is the type itself
    • SmplMath macros
Re: Heap problem
« Reply #1 on: September 13, 2014, 01:06:52 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

  • Member
  • ****
  • Posts: 868
Re: Heap problem
« Reply #2 on: September 13, 2014, 01:50:55 AM »
See above revamped code. Still does not work.

wjr

  • Member
  • **
  • Posts: 247
    • WJR's website
Re: Heap problem
« Reply #3 on: September 13, 2014, 02:12:58 AM »
Your [PtrMem] value in rcx will get changed with the call to ReadFile. Try using rbx or rdi instead if available.

qWord

  • Member
  • *****
  • Posts: 1475
  • The base type of a type is the type itself
    • SmplMath macros
Re: Heap problem
« Reply #4 on: September 13, 2014, 02:40:07 AM »
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

  • Member
  • ****
  • Posts: 868
Re: Heap problem
« Reply #5 on: September 14, 2014, 04:19:48 AM »
Problem solved.
Thread closed