10
20
30
40
50
60
70
80
90
100 :
110
120
130
140 :
150 :
160 DEFFNm_alloc(size%):LOCALA%,B%,E%:m_heap%=m_heap% :
170 IFm_heap%=0:PROCm_free(0) :
180 DIME%-1:IFsize%<1:=(HIMEM-E%-1280)AND(size%=0) :
190 size%=(size%+3)AND-4:
200
210 A%=m_heap%
220
230
240
250 A%=m_heap%
260 IFA%:IF!A%<size%:REPEATB%=A%:A%=A%!4:UNTIL!A%>=size%ORA%=0 :
270 :
280 IFA%:IF!A%<=size%:IFA%+!A%+4=E%:DIME%size%-!A%:!A%=size%:m_heap%=A%!4:=A%+4
290 :
300 IFA%:IF!A%>size%+7:A%!(size%+8)=A%!4:A%!(size%+4)=!A%-size%-4:A%!4=A%+size%+4:!A%=size%
310 IFA%=0:IFHIMEM-E%-size%-1280<0:=0 :
320 IFA%=0:DIMA%size%+3:!A%=size%:=A%+4 :
330 IFB%:B%!4=A%!4 ELSE m_heap%=A%!4 :
340 =A%+4 :
350 :
360 DEFPROCm_free(ptr%):m_heap%=m_heap%:IFptr%=0:ENDPROC
370 !ptr%=m_heap%:m_heap%=ptr%-4
380 IF!ptr%=ptr%+ptr%!-4:ptr%!-4=ptr%!-4+!!ptr%+4:!ptr%=!(!ptr%+4)
390 ENDPROC
400 :
410 DEFFNm_realloc(ptr%,size%):PROCm_free(ptr%):=FNm_alloc(size%)
420 :
430 DEFFNm_zalloc(size%):LOCALA%:A%=FNm_alloc(size%):IFA%=0ORsize%<1:=A%
440 REPEATsize%=size%-1:A%?size%=0:UNTILsize%<0:=A%