Panda3D
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
DeletedBufferChain Class Reference

This template class can be used to provide faster allocation/deallocation for many Panda objects. More...

#include "deletedBufferChain.h"

Public Member Functions

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 size associated with the DeletedBufferChain).
 
void deallocate (void *ptr, TypeHandle type_handle)
 Frees the memory for a buffer previously allocated via allocate().
 
size_t get_buffer_size () const
 Returns the size of the buffer that is actually returned at each request.
 
bool validate (void *ptr)
 Returns true if the pointer is valid, false if it has been deleted or if it was never a valid pointer.
 

Friends

class MemoryHook
 

Detailed Description

This template class can be used to provide faster allocation/deallocation for many Panda objects.

It works by maintaining a linked list of deleted buffers that are all of the same size; when a new object is allocated that matches that size, the same space is just reused.

This class manages untyped buffers of a fixed size. It can be used directly; or it also serves as a backbone for DeletedChain, which is a template class that manages object allocations.

Use MemoryHook to get a new DeletedBufferChain of a particular size.

Definition at line 58 of file deletedBufferChain.h.

Member Function Documentation

◆ allocate()

void * DeletedBufferChain::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 size associated with the DeletedBufferChain).

Definition at line 34 of file deletedBufferChain.cxx.

References NeverFreeMemory::alloc(), and TypeHandle::inc_memory_usage().

◆ deallocate()

void DeletedBufferChain::deallocate ( void * ptr,
TypeHandle type_handle )

Frees the memory for a buffer previously allocated via allocate().

Definition at line 102 of file deletedBufferChain.cxx.

References AtomicAdjustDummyImpl::compare_and_exchange(), and TypeHandle::dec_memory_usage().

◆ get_buffer_size()

size_t DeletedBufferChain::get_buffer_size ( ) const
inline

Returns the size of the buffer that is actually returned at each request.

Definition at line 39 of file deletedBufferChain.I.

◆ validate()

bool DeletedBufferChain::validate ( void * ptr)
inline

Returns true if the pointer is valid, false if it has been deleted or if it was never a valid pointer.

This is only meaningful in debug mode, where USE_DELETEDCHAINFLAG is defined. If not, this trivially returns true.

Definition at line 21 of file deletedBufferChain.I.

References AtomicAdjustDummyImpl::get().

Friends And Related Symbol Documentation

◆ MemoryHook

friend class MemoryHook
friend

Definition at line 103 of file deletedBufferChain.h.


The documentation for this class was generated from the following files: