22DeletedBufferChain(
size_t buffer_size) {
23 _deleted_chain =
nullptr;
24 _buffer_size = buffer_size;
27 _buffer_size = std::max(_buffer_size,
sizeof(ObjectNode));
36#ifdef USE_DELETED_CHAIN
40 assert(size <= _buffer_size);
43 const size_t alloc_size = _buffer_size + flag_reserved_bytes + MEMORY_HOOK_ALIGNMENT - 1;
48 if (_deleted_chain !=
nullptr) {
50 _deleted_chain = _deleted_chain->_next;
53#ifdef USE_DELETEDCHAINFLAG
54 assert(obj->_flag == (AtomicAdjust::Integer)DCF_deleted);
55 obj->_flag = DCF_alive;
58 void *ptr = node_to_buffer(obj);
63 type_handle.
inc_memory_usage(TypeHandle::MC_deleted_chain_active, alloc_size);
75 uintptr_t aligned = ((uintptr_t)mem + flag_reserved_bytes + MEMORY_HOOK_ALIGNMENT - 1) & ~(MEMORY_HOOK_ALIGNMENT - 1);
76 obj = (ObjectNode *)(aligned - flag_reserved_bytes);
78#ifdef USE_DELETEDCHAINFLAG
79 obj->_flag = DCF_alive;
82 void *ptr = node_to_buffer(obj);
85 assert(((uintptr_t)ptr % MEMORY_HOOK_ALIGNMENT) == 0);
89 type_handle.
inc_memory_usage(TypeHandle::MC_deleted_chain_active, alloc_size);
95 return PANDA_MALLOC_SINGLE(_buffer_size);
104#ifdef USE_DELETED_CHAIN
107 assert(ptr !=
nullptr);
109#ifdef DO_MEMORY_USAGE
110 const size_t alloc_size = _buffer_size + flag_reserved_bytes + MEMORY_HOOK_ALIGNMENT - 1;
111 type_handle.
dec_memory_usage(TypeHandle::MC_deleted_chain_active, alloc_size);
117 ObjectNode *obj = buffer_to_node(ptr);
119#ifdef USE_DELETEDCHAINFLAG
123 assert(orig_flag != (AtomicAdjust::Integer)DCF_deleted);
127 assert(orig_flag == (AtomicAdjust::Integer)DCF_alive);
132 obj->_next = _deleted_chain;
133 _deleted_chain = obj;
138 PANDA_FREE_SINGLE(ptr);
static Integer compare_and_exchange(Integer &mem, Integer old_value, Integer new_value)
Atomic compare and exchange.
void deallocate(void *ptr, TypeHandle type_handle)
Frees the memory for a buffer previously allocated via allocate().
void * allocate(size_t size, TypeHandle type_handle)
Allocates the memory for a new buffer of the indicated size (which must be no greater than the fixed ...
static void * alloc(size_t size)
Returns a pointer to a newly-allocated block of memory of the indicated size.
TypeHandle is the identifier used to differentiate C++ class types.
void dec_memory_usage(MemoryClass memory_class, size_t size)
Subtracts the indicated amount from the record for the total allocated memory for objects of this typ...
void inc_memory_usage(MemoryClass memory_class, size_t size)
Adds the indicated amount to the record for the total allocated memory for objects of this type.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.