MAlloc - Memory Allocation Library Routines =========================================== File: MAlloc - Update: 1.03 Author: J.G.Harston - Date: 23-Jul-2006 MAlloc provides functions and procedures to claim and release blocks of memory in the BASIC heap. The library keeps track of released memory and tries to reuse it as efficiently as possible. Requirements and Dependancies ============================= None. Routine Summary =============== FNm_alloc() - claim memory FNm_zalloc() - claim zeroed memory FNm_free() - release memory FNm_realloc() - resize claimed memory Claim Memory ============ DEFFNm_alloc(size%) Allocates size% bytes in the heap. Returns zero if failed, or pointer to memory block. Claim and Zero Memory ===================== DEFFNm_zalloc(size%) Allocates size% bytes in the heap and clears each byte of the allocated memory to zero. Returns zero if failed, or pointer to memory block. Release Memory ============== DEFPROCm_free(ptr%) Returns the specified block to the heap. If ptr% is zero, returns an amount of free claimable memory. Resize claimed memory ===================== DEFFNm_realloc(ptr%,size%) Reallocates the memory block to be the new size. If the pointer is zero a new block is created, If the size if 0 the block is freed. Returns a pointer to new block, or zero if failed. If data from old block needs to be preserved, it must be copied by the program between a m_alloc() call to claim new memory and a m_free() call to release the old memory. Notes ===== The current implementation does no memory checking. m_alloc() never returns zero, when there is no more heap space a "No room" error will occur. m_free() with a parameter of zero returns zero, implying no more heap space left. PROCm_free() and FNm_realloc() are undefined and potentially dangerous if ptr% is not a value previously returned from FNm_alloc or FNm_realloc(). Version History =============== 1.00 06-Sep-1989 m_alloc() and m_free() written. 1.01 08-Sep-1989 Bug in reuse of released memory fixed. 1.02 15-Sep-1989 m_realloc() added. 1.03 23-Jul-2006 m_zalloc() added.