37class EXPCL_DTOOL_DTOOLBASE MemoryHook {
40 MemoryHook(
const MemoryHook ©);
41 virtual ~MemoryHook();
55 constexpr static size_t get_memory_alignment() {
56 return MEMORY_HOOK_ALIGNMENT;
59 virtual void *
mmap_alloc(
size_t size,
bool allow_exec);
60 virtual void mmap_free(
void *ptr,
size_t size);
68 virtual void alloc_fail(
size_t attempted_size);
73 TVOLATILE AtomicAdjust::Integer _total_heap_single_size;
74 TVOLATILE AtomicAdjust::Integer _total_heap_array_size;
75 TVOLATILE AtomicAdjust::Integer _requested_heap_size;
76 TVOLATILE AtomicAdjust::Integer _total_mmap_size;
80 size_t _max_heap_size;
82 virtual void overflow_heap_size();
87 typedef std::map<size_t, DeletedBufferChain *> DeletedChains;
88 DeletedChains _deleted_chains;
90 mutable MutexImpl _lock;
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This template class can be used to provide faster allocation/deallocation for many Panda objects.
virtual void * mmap_alloc(size_t size, bool allow_exec)
Allocates a raw page or pages of memory directly from the OS.
virtual void mmap_free(void *ptr, size_t size)
Frees a block of memory previously allocated via mmap_alloc().
virtual void alloc_fail(size_t attempted_size)
This callback method is called whenever a low-level call to call_malloc() has returned NULL,...
virtual void * heap_alloc_array(size_t size)
Allocates a block of memory from the heap, similar to malloc().
DeletedBufferChain * get_deleted_chain(size_t buffer_size)
Returns a pointer to a global DeletedBufferChain object suitable for allocating arrays of the indicat...
void inc_heap(size_t size)
Called by our alternative malloc implementations (dlmalloc and ptmalloc2) to indicate they have reque...
virtual void heap_free_array(void *ptr)
Releases a block of memory previously allocated via heap_alloc_array.
virtual void * heap_alloc_single(size_t size)
Allocates a block of memory from the heap, similar to malloc().
virtual void mark_pointer(void *ptr, size_t orig_size, ReferenceCount *ref_ptr)
This special method exists only to provide a callback hook into MemoryUsage.
size_t round_up_to_page_size(size_t size) const
Rounds the indicated size request up to the next larger multiple of page_size, to qualify it for a ca...
virtual void heap_free_single(void *ptr)
Releases a block of memory previously allocated via heap_alloc_single.
static size_t get_ptr_size(void *ptr)
Given a pointer that was returned by a MemoryHook allocation, returns the number of bytes that were a...
bool heap_trim(size_t pad)
Attempts to release memory back to the system, if possible.
virtual void * heap_realloc_array(void *ptr, size_t size)
Resizes a block of memory previously returned from heap_alloc_array.
void dec_heap(size_t size)
Called by our alternative malloc implementations (dlmalloc and ptmalloc2) to indicate they have retur...
size_t get_page_size() const
Returns the operating system page size.
A base class for all things that want to be reference-counted.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.