&ô > BLib.MAlloc/src 1.05 15Sep2011 ,ô Version C: scans for exact match first ô (]ô v1.05 15Sep2011 JGH Extends last slot into free space, adds names to heap on first call 28ô v1.04 12Aug2006 JGH Checks for size of free memory <*ô v1.03 23Jul2006 JGH m_zalloc() added F+ô v1.02 15Sep1989 JGH m_realloc() added P?ô v1.01 08Sep1989 JGH Bug in reuse of released memory fixed Z8ô v1.00 06Sep1989 JGH m_alloc() and m_free() written d: n ô Memory Allocation Routines x ô ~~~~~~~~~~~~~~~~~~~~~~~~~~ ‚<ô *BUG* When scanning heap, when link=0, !0 is read from Œ: –:  @ݤm_alloc(size%):êA%,B%,E%:m_heap%=m_heap% :ô Create m_heap% ªUçm_heap%=0:òm_free(0) :ô If first call, add names to heap ´AÞE%-1:çsize%<1:=(“-E%-1280)€(size%=0) :ô Return free space ¾size%=(size%+3)€-4: È ÒA%=m_heap% Ürô IFA%:IFA%!4:REPEATB%=A%:A%=A%!4:UNTIL!A%=size%ORA%!4=0:IF!A%=size%:B%!4=A%!4:=A%+4 :REM Scan for exact slot æ ð úA%=m_heap% NçA%:ç!A%=size%„A%=0 :ô Scan for big enough slot R :ô Extend last slot JçA%:ç!A%<=size%:çA%+!A%+4=E%:ÞE%size%-!A%:!A%=size%:m_heap%=A%!4:=A%+4 "c :ô Slot bigger than needed, split it ,YçA%:ç!A%>size%+7:A%!(size%+8)=A%!4:A%!(size%+4)=!A%-size%-4:A%!4=A%+size%+4:!A%=size% 6RçA%=0:ç“-E%-size%-1280<0:=0 :ô No slot, no free space @WçA%=0:ÞA%size%+3:!A%=size%:=A%+4 :ô No slot, claim new space JNçB%:B%!4=A%!4 ‹ m_heap%=A%!4 :ô Get link, point to next slot TN=A%+4 :ô Return this claimed slot ^: h,Ýòm_free(ptr%):m_heap%=m_heap%:çptr%=0:á r !ptr%=m_heap%:m_heap%=ptr%-4 |Aç!ptr%=ptr%+ptr%!-4:ptr%!-4=ptr%!-4+!!ptr%+4:!ptr%=!(!ptr%+4) †á : š:ݤm_realloc(ptr%,size%):òm_free(ptr%):=¤m_alloc(size%) ¤: ®>ݤm_zalloc(size%):êA%:A%=¤m_alloc(size%):çA%=0„size%<1:=A% ¸*õsize%=size%-1:A%?size%=0:ýsize%<0:=A% ÿ