REM > JLibraries:Heap.2
REM © James Bursa, 1997

REM JB  16 Nov 1997     created


DEF PROCHeap_Init(Anch%)
Task_HeapBase% = HIMEM
SYS"WimpExt_Heap", 0, HIMEM, Anch%
ENDPROC

REM ˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜

DEF FNHeap_Alloc(Size%)
LOCAL Anch%
SYS"WimpExt_Heap", 2 ,, Size% TO ,Anch%
=Anch%

REM ˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜

DEF PROCHeap_Free(Anch%)
SYS"WimpExt_Heap", 3, Anch%
ENDPROC

REM ˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜

DEF FNHeap_ReAlloc(Anch%, Size%)
LOCAL Flag%
SYS"WimpExt_Heap", 4, Anch%, Size% TO , Flag%
=(Flag% <> 0)

REM ˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜

DEF FNHeap_Grab(Size%, Word%, Name$)
LOCAL Anch%
SYS"WimpExt_Heap", 2,, Size% TO , Anch%
IF Anch% > 0 THEN PROCObject_Add(4, Anch%, Word%, Name$)
=(Anch% <> 0)

REM ˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜

DEF FNHeap_Safe(Size%, Word%, Name$)
IF NOT FNHeap_Grab(Size%, Word%, Name$) THEN ERROR Erro_Memo%, ""
=FNHeap_Find(Word%, Name$)

REM ˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜

DEF FNHeap_Find(Word%, Name$)
Hand% = FNObject_Hand(4, Name$, Word%)
IF Hand% = &7FFFFFFF THEN ERROR 1, ("FNHeap_Find: "+Name$+", "+STR$Word%)
=!Hand%

REM ˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜

DEF PROCHeap_Lose(Word%, Name$)
LOCAL Hand%
 IF Name$ = "*" THEN
  Hand% = FNObject_Find(4, Word%)
   WHILE Hand% <> &7FFFFFFF
    SYS"WimpExt_Heap", 3, Hand%
    PROCObject_Remove(4, Hand%, Word%)
    Hand% = FNObject_Find(4, Word%)
   ENDWHILE
 ELSE
  Hand% = FNObject_Hand(4, Name$, Word%)
   IF Hand% <> &7FFFFFFF THEN
    SYS"WimpExt_Heap", 3, Hand%
    PROCObject_Remove(4, Hand%, Word%)
   ENDIF
 ENDIF
ENDPROC
