void Heap::Free(void *ptr) { if(!ptr) return; LLOG("Free " << ptr); if((((dword)(uintptr_t)ptr) & 8) == 0) { Page *page = (Page *)((uintptr_t)ptr & ~(uintptr_t)4095); int k = page->klass; LLOG("Small free page: " << (void *)page << ", k: " << k << ", ksz: " << Ksz(k)); ASSERT((4096 - ((uintptr_t)ptr & (uintptr_t)4095)) % Ksz(k) == 0); #ifdef _MULTITHREADED if(page->heap != this) { // freeing page allocated in different thread page->heap->RemoteFree(ptr); // add to original heap's list of free pages to be properly freed later return; } #endif DbgFreeFillK(ptr, k); if(cachen[k]) { cachen[k]--; FreeLink *l = (FreeLink *)ptr; l->next = cache[k]; cache[k] = l; return; } FreeK(ptr, page, k); } else LFree(ptr); }
void Heap::SmallFreeDirect(void *ptr) { // does not need to check for target heap or small vs large LLOG("Free Direct " << ptr); Page *page = GetPage(ptr); ASSERT(page->heap == this); int k = page->klass; LLOG("Small free page: " << (void *)page << ", k: " << k << ", ksz: " << Ksz(k)); ASSERT((4096 - ((uintptr_t)ptr & (uintptr_t)4095)) % Ksz(k) == 0); DbgFreeFillK(ptr, k); FreeK(ptr, page, k); }
void Heap::FreeDirect(void *ptr) { LLOG("Free Direct " << ptr); if((((dword)(uintptr_t)ptr) & 8) == 0) { Page *page = (Page *)((uintptr_t)ptr & ~(uintptr_t)4095); int k = page->klass; LLOG("Small free page: " << (void *)page << ", k: " << k << ", ksz: " << Ksz(k)); ASSERT((4096 - ((uintptr_t)ptr & (uintptr_t)4095)) % Ksz(k) == 0); DbgFreeFillK(ptr, k); FreeK(ptr, page, k); } else LFree(ptr); }
force_inline void Heap::Free(void *ptr, Page *page, int k) { LLOG("Small free page: " << (void *)page << ", k: " << k << ", ksz: " << Ksz(k)); ASSERT((4096 - ((uintptr_t)ptr & (uintptr_t)4095)) % Ksz(k) == 0); #ifdef _MULTITHREADED if(page->heap != this) { // freeing page allocated in different thread RemoteFree(ptr, Ksz(k)); // add to originating heap's list of free pages to be properly freed later return; } #endif DbgFreeFillK(ptr, k); if(cachen[k]) { cachen[k]--; FreeLink *l = (FreeLink *)ptr; l->next = cache[k]; cache[k] = l; return; } FreeK(ptr, page, k); }
inline void Heap::Free48(void *ptr) { Page *page = (Page *)((uintptr_t)ptr & ~(uintptr_t)4095); LLOG("Small free page: " << (void *)page << ", k: " << k << ", ksz: " << Ksz(k)); ASSERT((4096 - ((uintptr_t)ptr & (uintptr_t)4095)) % Ksz(2) == 0); #ifdef _MULTITHREADED if(page->heap != this) { page->heap->RemoteFree(ptr); return; } #endif DbgFreeFillK(ptr, 2); if(cachen[2]) { cachen[2]--; FreeLink *l = (FreeLink *)ptr; l->next = cache[2]; cache[2] = l; return; } FreeK(ptr, page, 2); }