' *** MEMBLOCK.LST *** 2nd GFA-Manual, page 4-8 > PROCEDURE memory_block(bytes%,VAR adr%) ' ' *** Create a memory-block for this program of length bytes% ' *** Address adr% of memory-block is returned (0 = error) ' *** RESERVE is used first if not enough memory available for MALLOC ' *** At least 16 K is left for GEM ' *** At least 2000 bytes of free memory are left for this program ' *** Always call Procedure Memory_block_free before ending this program! ' ' *** Procedure: Program_exit ' LOCAL m$,k bytes%=AND(ADD(bytes%,255),&HFFFFFF00) ! multiple of 256 IF (MALLOC(-1)-bytes%)>=16*1024 ! enough memory available adr%=MALLOC(bytes%) ELSE ! not enough memory available IF FRE()>(bytes%+2000) ! safety-margin of 2000 bytes RESERVE -bytes% ! shrink program-memory adr%=MALLOC(bytes%) ELSE ! definitely not enough memory m$=" *** Error ***|Procedure Memory_block could |not create" m$=m$+" a memory-block |of "+STR$(bytes%)+" bytes" ALERT 3,m$,1,"Quit|Continue",k IF k=1 @program_exit ENDIF ENDIF ENDIF RETURN ' *** > PROCEDURE memory_block_free(adr%) ' ' *** Release memory-block at address adr% (created by Procedure Memory_block) ' IF adr%>0 ~MFREE(adr%) ENDIF RESERVE RETURN ' ********* '