21 static const size_t min_page_remaining_size = 16;
24 static const size_t min_page_size = 128 * 1024;
38 void *NeverFreeMemory::
39 ns_alloc(
size_t size) {
49 Pages::iterator pi = _pages.lower_bound(Page(
nullptr, size));
50 if (pi != _pages.end()) {
54 void *result = page.alloc(size);
55 if (page._remaining >= min_page_remaining_size) {
64 size_t needed_size = std::max(size, min_page_size);
66 void *start = memory_hook->
mmap_alloc(needed_size,
false);
67 _total_alloc += needed_size;
69 Page page(start, needed_size);
70 void *result = page.alloc(size);
71 if (page._remaining >= min_page_remaining_size) {
81 void NeverFreeMemory::
85 ((
void * TVOLATILE &)_global_ptr,
nullptr, (
void *)ptr);
86 if (result !=
nullptr) {
This class is used to allocate bytes of memory from a pool that is never intended to be freed.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void * mmap_alloc(size_t size, bool allow_exec)
Allocates a raw page or pages of memory directly from the OS.
static Pointer compare_and_exchange_ptr(Pointer &mem, Pointer old_value, Pointer new_value)
Atomic compare and exchange.