14#ifndef SIMPLEALLOCATOR_H
15#define SIMPLEALLOCATOR_H
29class EXPCL_PANDA_GOBJ SimpleAllocator :
public LinkedListNode {
31 INLINE
explicit SimpleAllocator(
size_t max_size,
Mutex &lock);
32 SimpleAllocator(SimpleAllocator &&from)
noexcept;
33 virtual ~SimpleAllocator();
35 INLINE SimpleAllocatorBlock *
alloc(
size_t size,
size_t alignment=1);
45 void output(std::ostream &out)
const;
46 void write(std::ostream &out)
const;
49 SimpleAllocatorBlock *do_alloc(
size_t size,
size_t alignment=1);
50 INLINE
bool do_is_empty()
const;
52 virtual SimpleAllocatorBlock *make_block(
size_t start,
size_t size);
53 INLINE
void mark_contiguous(
const LinkedListNode *block);
54 virtual void changed_contiguous();
84 friend class SimpleAllocatorBlock;
90class EXPCL_PANDA_GOBJ SimpleAllocatorBlock :
public LinkedListNode {
92 INLINE SimpleAllocatorBlock(SimpleAllocator *alloc,
93 size_t start,
size_t size);
96 SimpleAllocatorBlock() =
default;
97 SimpleAllocatorBlock(
const SimpleAllocatorBlock ©) =
delete;
98 INLINE SimpleAllocatorBlock(SimpleAllocatorBlock &&from);
100 SimpleAllocatorBlock &operator = (
const SimpleAllocatorBlock ©) =
delete;
101 INLINE SimpleAllocatorBlock &operator = (SimpleAllocatorBlock &&from);
104 INLINE ~SimpleAllocatorBlock();
114 INLINE
bool realloc(
size_t size);
118 void output(std::ostream &out)
const;
121 INLINE
void do_free();
122 INLINE
size_t do_get_max_size()
const;
123 INLINE
bool do_realloc(
size_t size);
126 SimpleAllocator *_allocator =
nullptr;
130 friend class SimpleAllocator;
133INLINE std::ostream &operator << (std::ostream &out,
const SimpleAllocator &obj) {
A standard mutex, or mutual exclusion lock.
A single block as returned from SimpleAllocator::alloc().
bool realloc(size_t size)
Changes the size of this block to the specified size.
SimpleAllocator * get_allocator() const
Returns the SimpleAllocator object that owns this block.
bool is_free() const
Returns true if the block has been freed, false if it is still valid.
SimpleAllocatorBlock * get_next_block() const
Returns a pointer to the next allocated block in the chain, or NULL if there are no more allocated bl...
size_t get_size() const
Returns the size of this block.
size_t get_max_size() const
Returns the maximum size this block can be reallocated to, as limited by the following block.
size_t get_start() const
Returns the starting point of this block.
void free()
Releases the allocated space.
An implementation of a very simple block allocator.
size_t get_total_size() const
Returns the total size of allocated objects.
size_t get_max_size() const
Returns the available space for allocated objects.
size_t get_contiguous() const
Returns an upper-bound estimate of the size of the largest contiguous block that may be allocated.
SimpleAllocatorBlock * get_first_block() const
Returns a pointer to the first allocated block, or NULL if there are no allocated blocks.
void set_max_size(size_t max_size)
Changes the available space for allocated objects.
bool is_empty() const
Returns true if there are no blocks allocated on this page, or false if there is at least one.
SimpleAllocatorBlock * alloc(size_t size, size_t alignment=1)
Allocates a new block.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.