MEMORY(1) AMIGA DOS EXEC FUNCTIONS MEMORY(1) NAME Allocate(), Deallocate(), AllocMem(), AllocAbs(), FreeMem(), AvailMem(), AllocEntry(), FreeEntry(). SYNOPSIS void *Allocate(struct MemHeader *freeList, ULONG byteSize) (A0,D0) void Deallocate(struct MemHeader *freeList, APTR memoryBlock, ULONG byteSize) (A0/A1,D0) void *AllocMem(ULONG byteSize, ULONG requirements) (D0/D1) void *AllocAbs(ULONG byteSize, APTR location) (D0/D1) void FreeMem(void *memoryBlock, ULONG byteSize) (A1,D0) ULONG AvailMem(ULONG requirements) (D1) struct MemList * AllocEntry(struct MemList *entry) (A0) void FreeEntry(struct MemList *entry) (A0) LIBRARY Exec OFFSET Allocate 0xba Deallocate 0xc0 AllocMem 0xc6 AllocAbs 0xcc FreeMem 0xd2 AvailMem 0xd8 AllocEntry 0xde FreeEntry 0xe4 DESCRIPTION The following functions use the following structures to allocate and organize blocks of memory: struct MemChunk { struct MemChunk *mc_Next; /* pointer to next chunk */ ULONG mc_Bytes; /* chunk byte size */ } struct MemHeader { struct Node mh_Node; UWORD mh_Attributes; /* characteristics of this region */ struct MemChunk *mh_First; /* first free region */ APTR mh_Lower; /* lower memory bound */ APTR mh_Upper; /* upper memory bound+1 */ ULONG mh_Free; /* total number of free byte */ } struct MemEntry { union { ULONG meu_Reqs; /* the AllocMem requirements */ APTR meu_Addr; /* the address of this memory region */ } me_Un; ULONG me_Length; /* the length of this memory region */ } struct MemList { struct Node ml_Node; UWORD ml_NumEntries; /* number of entries in this struct */ struct MemEntry ml_ME[1]; /* the first entry */ } FUNCTIONS - Allocate : to allocate memory using a region header. First a block of memory must be allocated (typically with AllocMem.), and the MemHeader structure must be initialized so to point to all or part of that block. Then, call to Allocate will allocate small chunks of memory from that big block. freeList : pointer to the MemHeader structure. byteSize : the size of memory to allocate. return : pointer to start of the allocated memory. - Deallocate : frees memory allocated with Allocate. Eventually the block of memory allocated to initialize the MemHeader must be be freed (typically with FreeMem.) freeList : pointer to the MemHeader structure. memoryBlock : pointer to the memory to free. byteSize : the size of memory to free. - AllocMem : to allocate a block of memory of a given size and type. If requirement is zero, FAST memory is search first, and then CHIP memory. byteSize : the size of memory to allocate. requirements: memory requirement flags: MEMF_CHIP : ask for CHIP memory. MEMF_FAST : ask for FAST memory. MEMF_PUBLIC : ask for public memory, that is memory that is accessible buy other tasks. MEMF_CLEAR : clear memory before returning. - AllocAbs : to allocate a memory block starting at a specified address. byteSize : the size of memory to allocate. location : pointer to the memory to allocate. - FreeMem : frees memory allocated by AllocMem. The first argument must be a pointer returned by AllocMem, and the byteSize must be the same as the one given to AllocMem. memoryBlock : pointer to the memory to free. byteSize : the size of the block to free. - AvailMem : returns the amount of available memory. requirements: to test a type of memory (CHIP, FAST ... ), using the same flags as with AllocMem. - AllocEntry : to allocate more than one block of memory at a time. The argument is a MemList that contains the information about the size and type of memory to allocate. entry : pointer to the initialized MemList. return : a pointer to a new MemList if the allocation is successful. If one of the block can't be allocated, the returned value has the bit 31 set, and correspond to the memory requirement that caused the problem. - FreeEntry : to free memory blocks allocated by AllocEntry. entry : pointer to the MemList as returned by AllocEntry. SEE ALSO lists, AllocRemember, FreeRemember.