// // Memory allocators for CssmHeap objects. // This implementation stores a pointer to the allocator used into memory // *after* the object's proper storage block. This allows the usual free() // functions to safely free our (hidden) pointer without knowing about it. // An allocator argument of NULL is interpreted as the standard allocator. // void *CssmHeap::operator new (size_t size, Allocator *alloc) throw(std::bad_alloc) { if (alloc == NULL) alloc = &Allocator::standard(); size = alignUp(size, alignof_template<Allocator *>()); size_t totalSize = size + sizeof(Allocator *); void *addr = alloc->malloc(totalSize); *(Allocator **)increment(addr, size) = alloc; return addr; }
void CssmHeap::operator delete (void *addr, size_t size) throw() { void *end = increment(addr, alignUp(size, alignof_template<Allocator *>())); (*(Allocator **)end)->free(addr); }