The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Farabi on February 20, 2012, 08:57:43 AM

Title: Alloc Function causing crashes
Post by: Farabi on February 20, 2012, 08:57:43 AM
Alloc funciton is limited to less than 1000 handle. I tried to allocating 87142 handle and it is crashed, it seems to be the handle table used is minimum, changing it to globalalloc and everything went fine again.

I'd suggest this for replacement

mAlloc proc nSize:dword

add nSize,4
invoke GlobalAlloc,GMEM_ZEROINIT or GMEM_FIXED,nSize
.if eax==0
invoke MessageBox,NULL,CADD("Unable to allocate memory"),NULL,MB_OK
.endif

ret
mAlloc endp
Title: Re: Alloc Function causing crashes
Post by: dedndave on February 20, 2012, 03:17:44 PM
QuoteI tried to allocating 87142 handle and it is crashed

:eek

i am surprised you got to 87141   :lol

allocate fewer large blocks, then split them up with pointers
Title: Re: Alloc Function causing crashes
Post by: MichaelW on February 20, 2012, 03:44:06 PM
I doubt that many people use the Alloc procedure. A more reasonable choice is to use the alloc macro (which calls GlobalAlloc with GMEM_ZEROINIT or GMEM_FIXED), and check the returned pointer.