void free ( /* SYNOPSIS */ void * memory) /* FUNCTION Return memory allocated with malloc() or a similar function to the system. INPUTS memory - The result of the previous call to malloc(), etc. or NULL. RESULT None. NOTES This function must not be used in a shared library or in a threaded application. EXAMPLE BUGS SEE ALSO malloc() INTERNALS ******************************************************************************/ { if (memory) { unsigned char *mem; size_t size; mem = ((UBYTE *)memory) - AROS_ALIGN(sizeof(size_t)); size = *((size_t *) mem); if (size == MEMALIGN_MAGIC) free(((void **) mem)[-1]); else { size += AROS_ALIGN(sizeof(size_t)); FreePooled (__startup_mempool, mem, size); } } } /* free */
AROS_UFH3(struct BattClockBase *, AROS_SLIB_ENTRY(init,BASENAME), AROS_UFHA(ULONG, dummy, D0), AROS_UFHA(ULONG, slist, A0), AROS_UFHA(struct ExecBase *, SysBase, A6) ) { UWORD neg = AROS_ALIGN(LIB_VECTSIZE * 3); struct BattClockBase * BattClockBase = NULL; BattClockBase = (struct BattClockBase *)(((UBYTE *) AllocMem( neg + sizeof(struct BattClockBase), MEMF_CLEAR | MEMF_PUBLIC)) + neg); if( BattClockBase ) { BattClockBase->bb_SysBase = SysBase; BattClockBase->bb_UtilBase = OpenLibrary("utility.library",0); BattClockBase->bb_Node.ln_Pri = 0; BattClockBase->bb_Node.ln_Type = NT_RESOURCE; BattClockBase->bb_Node.ln_Name = (STRPTR)name; MakeFunctions(BattClockBase, (APTR)LIBFUNCTABLE, NULL); AddResource(BattClockBase); } return BattClockBase; }
APTR ReAllocVec ( /* SYNOPSIS */ APTR oldmem, ULONG newsize, ULONG requirements) /* FUNCTION Change the size of an AllocVec:ed part of memory. The memory must have been allocated by AllocVec(). If you reduce the size, the old contents will be lost. If you enlarge the size, the new contents will be undefined. INPUTS oldmen - What you got from AllocVec(). newsize - The new size. requirements - The (new) requirements. Note that if no new block of memory is allocated, the requirements are not considered. RESULT A pointer to the allocated memory or NULL. If you don't need the memory anymore, you can pass this pointer to FreeVec(). NOTES If you get NULL, the memory at oldmem will not have been freed and can still be used. Note that if no new block of memory is allocated, the requirements are not considered. This function must not be used in a shared library or in a threaded application. (???) EXAMPLE BUGS SEE ALSO exec.library/AllocVec(), exec.library/FreeVec(), exec.library/CopyMem() INTERNALS HISTORY ******************************************************************************/ { // AROS_LIBFUNC_INIT UBYTE * mem, * newmem; ULONG oldsize; if (!oldmem) return AllocVec (newsize, requirements); mem = (UBYTE *)oldmem - AROS_ALIGN(sizeof(ULONG)); oldsize = *((ULONG *)mem) - sizeof(ULONG); /* Reduce or enlarge the memory ? */ if (newsize < oldsize) { /* Don't change anything for small changes */ if ((oldsize - newsize) < REALLOC_MINDECREASE) newmem = oldmem; else goto copy; } else if (newsize == oldsize) /* Keep the size ? */ newmem = oldmem; else { /* It is likely that if memory is ReAllocVec:ed once it will be ReAllocVec:ed again, so don't be too stingy with memory */ if ((newsize - oldsize) < REALLOC_MININCREASE) newsize = oldsize + REALLOC_MININCREASE; copy: newmem = AllocVec(newsize, requirements); if (newmem) { CopyMem (oldmem, newmem, newsize); FreeVec (oldmem); } } return newmem; // AROS_LIBFUNC_EXIT } /* ReAllocVec */