I can use calling:
!PUSH dword [_PB_MemoryBase]
!CALL _HeapDestroy@4
I can use calling:
!PUSH dword 0
!PUSH dword 4096
!PUSH dword 8
!CALL _HeapCreate@12
!MOV [PB_MemoryBase], EAX
But can't calling:
!CALL _HeapAlloc@12
&
!CALL _HeapReAlloc@16
Error: undefined symbol
How to call _HeapAlloc@12 & _HeapReAlloc@16 ?
How to call _HeapAlloc@12 & _HeapReAlloc@16 ?
Re: How to call _HeapAlloc@12 & _HeapReAlloc@16 ?
Look in the commented asm, you need to import them before using (just reference HeapCreate_() somewhere in your PB code and it will be the same).
Re: How to call _HeapAlloc@12 & _HeapReAlloc@16 ?
I have a few questions.Fred wrote:Look in the commented asm, you need to import them before using (just reference HeapCreate_() somewhere in your PB code and it will be the same).
1. For what in the PureBasic is specially refused the HeapAlloc and HeapReAlloc with zero size?
Possibility to create zero size blocks is very usefuly.
2. For what in PureBasic creating one more Heap (HEAP_ID is storing into the [_PB_MemoryBase]), instead using default task HEAP_ID, that available via the GetProcessHeap()?
This functions into the PureBasic library working with the HEAP_ZERO_MEMORY flag, but check size parameter & generate the error when size is zero:
AllocateMemory (HeapAlloc):
Code: Select all
MOV EAX, [DWORD SS:ESP+4] ; !!!
TEST EAX, EAX ; !!! if SIZE = 0
JLE do_Return_False ; !!! Then Return #False
PUSH EAX
MOV EAX, [_PB_MemoryBase]
PUSH 8 ; flag = HEAP_ZERO_MEMORY
PUSH EAX
CALL NEAR [DWORD DS:<&KERNEL32.HeapAlloc>]
RETN 4
do_Return_False: XOR EAX, EAX
RETN 4
Code: Select all
MOV ECX, [DWORD SS:ESP+8] ; !!!
TEST ECX, ECX ; !!! if SIZE is 0
JLE do_Return_False ; !!! Then Return #False
MOV EAX, [DWORD SS:ESP+4]
TEST EAX, EAX
PUSH ECX
JE do_HeapAlloc
PUSH EAX
MOV EAX, [_PB_MemoryBase]
PUSH 8 ; flag = HEAP_ZERO_MEMORY
PUSH EAX
CALL NEAR [DWORD DS:<&KERNEL32.HeapReAlloc>]
RETN 8
do_HeapAlloc: CALL AllocateMemory
RETN 8
do_Return_False: XOR EAX, EAX
RETN 8
See ya... 

Re: How to call _HeapAlloc@12 & _HeapReAlloc@16 ?
Why is it useful to allocate a 0 bytes memory area ?
Re: How to call _HeapAlloc@12 & _HeapReAlloc@16 ?
Functions the AllocateMemory and ReAllocateMemory in windose PureBasic versions should not be a procedure, it must be a macro to create the calls to HeapAlloc and HeapReAlloc.Fred wrote:Why is it useful to allocate a 0 bytes memory area ?
Compiled application should not be used initially artificially created with the storage identifier Heap in this variable [_PB_MemoryBase].
This is unnatural and incompatible with a common method through GetProcessHeap().
The functions HeapAlloc and HeapReAlloc themselves are bullproof.
Ability to create zero-sized blocks specially laid well the OS level.
Because it allows a very flexible to work with pre-created buffer, further fulfilling dynamic change buffer size.
I often use this feature when working with a structured management, especially when working with files stored resources (SFX, VFX, e.t.c.), working with the Chunks-based files (resources containers, resources into the firmwares, e.t.c.).
Into the PureBasic this is impossible, not because the procedures can not do that, but because the caps before the procedures:
MOV EAX, [DWORD SS:ESP+4]
TEST EAX, EAX ; !!! if SIZE = 0
JLE do_Return_False ; !!! Then Return #False
And why deny the possibility of artificially already implemented in the OS API?
If you remove the caps and will use heap of task GetProcessHeap(), will not suffer from the compatibility and completeness of the functions will be possible.
IMHO
See ya... 

Re: How to call _HeapAlloc@12 & _HeapReAlloc@16 ?
You are right, this working as in pure FASM:Fred wrote:Look in the commented asm, you need to import them before using (just reference HeapCreate_() somewhere in your PB code and it will be the same).
Code: Select all
!if ~ defined _HeapAlloc@12
!extrn _HeapAlloc@12
!end if
!if ~ defined _HeapReAlloc@14
!extrn _HeapAlloc@14
!end if
See ya... 
