22 DeletedBufferChain(
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 39 assert(size <= _buffer_size);
42 const size_t alloc_size = _buffer_size + flag_reserved_bytes + MEMORY_HOOK_ALIGNMENT - 1;
47 if (_deleted_chain !=
nullptr) {
49 _deleted_chain = _deleted_chain->_next;
52 #ifdef USE_DELETEDCHAINFLAG 53 assert(obj->_flag == (AtomicAdjust::Integer)DCF_deleted);
54 obj->_flag = DCF_alive;
55 #endif // USE_DELETEDCHAINFLAG 57 void *ptr = node_to_buffer(obj);
59 #ifdef DO_MEMORY_USAGE 62 type_handle.
inc_memory_usage(TypeHandle::MC_deleted_chain_active, alloc_size);
63 #endif // DO_MEMORY_USAGE 74 uintptr_t aligned = ((uintptr_t)mem + flag_reserved_bytes + MEMORY_HOOK_ALIGNMENT - 1) & ~(MEMORY_HOOK_ALIGNMENT - 1);
75 obj = (ObjectNode *)(aligned - flag_reserved_bytes);
77 #ifdef USE_DELETEDCHAINFLAG 78 obj->_flag = DCF_alive;
79 #endif // USE_DELETEDCHAINFLAG 81 void *ptr = node_to_buffer(obj);
84 assert(((uintptr_t)ptr % MEMORY_HOOK_ALIGNMENT) == 0);
87 #ifdef DO_MEMORY_USAGE 88 type_handle.
inc_memory_usage(TypeHandle::MC_deleted_chain_active, alloc_size);
89 #endif // DO_MEMORY_USAGE 93 #else // USE_DELETED_CHAIN 94 return PANDA_MALLOC_SINGLE(_buffer_size);
95 #endif // USE_DELETED_CHAIN 103 #ifdef USE_DELETED_CHAIN 106 assert(ptr !=
nullptr);
108 #ifdef DO_MEMORY_USAGE 109 const size_t alloc_size = _buffer_size + flag_reserved_bytes + MEMORY_HOOK_ALIGNMENT - 1;
110 type_handle.
dec_memory_usage(TypeHandle::MC_deleted_chain_active, alloc_size);
114 #endif // DO_MEMORY_USAGE 116 ObjectNode *obj = buffer_to_node(ptr);
118 #ifdef USE_DELETEDCHAINFLAG 122 assert(orig_flag != (AtomicAdjust::Integer)DCF_deleted);
126 assert(orig_flag == (AtomicAdjust::Integer)DCF_alive);
127 #endif // USE_DELETEDCHAINFLAG 131 obj->_next = _deleted_chain;
132 _deleted_chain = obj;
136 #else // USE_DELETED_CHAIN 137 PANDA_FREE_SINGLE(ptr);
138 #endif // USE_DELETED_CHAIN PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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 ...
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.
void deallocate(void *ptr, TypeHandle type_handle)
Frees the memory for a buffer previously allocated via allocate().
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...
static Integer compare_and_exchange(Integer &mem, Integer old_value, Integer new_value)
Atomic compare and exchange.