struct mem_block * u_mmAllocMem(struct mem_block *heap, int size, int align2, int startSearch) { struct mem_block *p; const int mask = (1 << align2)-1; int startofs = 0; int endofs; assert(size >= 0); assert(align2 >= 0); assert(align2 <= 12); /* sanity check, 2^12 (4KB) enough? */ if (!heap || align2 < 0 || size <= 0) return NULL; for (p = heap->next_free; p != heap; p = p->next_free) { assert(p->free); startofs = (p->ofs + mask) & ~mask; if ( startofs < startSearch ) { startofs = startSearch; } endofs = startofs+size; if (endofs <= (p->ofs+p->size)) break; } if (p == heap) return NULL; assert(p->free); p = SliceBlock(p,startofs,size,0,mask+1); return p; }
PMemBlock mmAllocMem( memHeap_t *heap, int size, int align2, int startSearch) { int mask,startofs,endofs; TMemBlock *p; if (!heap || align2 < 0 || size <= 0) return NULL; mask = (1 << align2)-1; startofs = 0; p = (TMemBlock *)heap; while (p) { if ((p)->free) { startofs = (p->ofs + mask) & ~mask; if ( startofs < startSearch ) { startofs = startSearch; } endofs = startofs+size; if (endofs <= (p->ofs+p->size)) break; } p = p->next; } if (!p) return NULL; p = SliceBlock(p,startofs,size,0,mask+1); p->heap = heap; return p; }
struct mem_block * mmAllocMem(struct mem_block *heap, unsigned size, unsigned align2, unsigned startSearch) { struct mem_block *p; const unsigned mask = (1 << align2)-1; unsigned startofs = 0; unsigned endofs; if (!heap || !align2 || !size) return NULL; for (p = heap->next_free; p != heap; p = p->next_free) { assert(p->free); startofs = (p->ofs + mask) & ~mask; if ( startofs < startSearch ) { startofs = startSearch; } endofs = startofs+size; if (endofs <= (p->ofs+p->size)) break; } if (p == heap) return NULL; assert(p->free); p = SliceBlock(p,startofs,size,0,mask+1); return p; }
int mmReserveMem(memHeap_t *heap, int offset,int size) { int endofs; TMemBlock *p; if (!heap || size <= 0) return -1; endofs = offset+size; p = (TMemBlock *)heap; while (p && p->ofs <= offset) { if (ISFREE(p) && endofs <= (p->ofs+p->size)) { SliceBlock(p,offset,size,1,1); return 0; } p = p->next; } return -1; }
struct mem_block * u_mmAllocMem(struct mem_block *heap, int size, int align2, int startSearch) { struct mem_block *p; const int mask = (1 << align2)-1; int startofs = 0; int endofs; assert(size >= 0); assert(align2 >= 0); /* Make sure that a byte alignment isn't getting passed for our * power-of-two alignment arg. */ assert(align2 < 32); if (!heap || align2 < 0 || size <= 0) return NULL; for (p = heap->next_free; p != heap; p = p->next_free) { assert(p->free); startofs = (p->ofs + mask) & ~mask; if ( startofs < startSearch ) { startofs = startSearch; } endofs = startofs+size; if (endofs <= (p->ofs+p->size)) break; } if (p == heap) return NULL; assert(p->free); p = SliceBlock(p,startofs,size,0,mask+1); return p; }