18#ifndef __LIBALLOC_ALLOCATOR_H
19#define __LIBALLOC_ALLOCATOR_H
25#pragma GCC diagnostic push
26#pragma GCC diagnostic ignored "-Wnew-returns-null"
207inline void *
operator new(__SIZE_TYPE__ sz)
211 alloc_args.
size = sz;
215 return (
void *) alloc_args.
address;
217 return (
void *)
NULL;
225inline void *
operator new[](__SIZE_TYPE__ sz)
229 alloc_args.
size = sz;
233 return (
void *) alloc_args.
address;
235 return (
void *)
NULL;
243inline void operator delete (
void *mem)
253inline void operator delete[] (
void *mem)
266inline void *
operator new(__SIZE_TYPE__ sz,
Address addr)
268 return (
void *) addr;
Allocator * m_parent
Our parent Allocator, if any.
virtual Result release(const Address addr)
Release memory.
Range m_range
Range of memory that this Allocator manages.
Allocator * parent()
Get parent Allocator.
static void setDefault(Allocator *alloc)
Makes the given Allocator the default.
virtual Size available() const
Get memory available.
Address base() const
Get memory base address for allocations.
virtual Size size() const
Get memory size.
Size alignment() const
Get memory alignment in bytes for allocations.
Allocator()
Default class constructor.
virtual Result allocate(Range &range)
Allocate memory.
void setParent(Allocator *parent)
Set parent allocator.
static Allocator * m_default
Points to the default Allocator for new()/delete().
virtual ~Allocator()
Class destructor.
static Allocator * getDefault()
Retrieve the currently default Allocator.
Result
Allocation results.
Address aligned(const Address addr, const Size boundary) const
Align memory address.
#define NULL
NULL means zero.
unsigned long Address
A memory address.
unsigned int Size
Any sane size indicator cannot go negative.
Describes a range of memory.
Size alignment
Alignment in bytes or ZERO for default alignment.
Address address
Starting address of the memory range.
Size size
Amount of memory in bytes.