FreeNOS
Public Member Functions | Private Attributes | Static Private Attributes
PageAllocator Class Reference

Allocates virtual memory using the memory server. More...

#include <PageAllocator.h>

Inheritance diagram for PageAllocator:
Allocator

Public Member Functions

 PageAllocator (const Range range)
 Class constructor. More...
 
virtual Size available () const
 Get memory available. More...
 
virtual Result allocate (Range &args)
 Allocate memory. More...
 
virtual Result release (const Address addr)
 Release memory. More...
 
- Public Member Functions inherited from Allocator
 Allocator ()
 Default class constructor. More...
 
 Allocator (const Range range)
 Class constructor with Range input. More...
 
virtual ~Allocator ()
 Class destructor. More...
 
void setParent (Allocator *parent)
 Set parent allocator. More...
 
Allocatorparent ()
 Get parent Allocator. More...
 
Address base () const
 Get memory base address for allocations. More...
 
Size alignment () const
 Get memory alignment in bytes for allocations. More...
 
virtual Size size () const
 Get memory size. More...
 

Private Attributes

Size m_allocated
 Total number of bytes allocated. More...
 

Static Private Attributes

static const Size MinimumAllocationSize = PAGESIZE * 32U
 Minimum size required for allocations. More...
 

Additional Inherited Members

- Public Types inherited from Allocator
enum  Result {
  Success = 0, InvalidAddress, InvalidSize, InvalidAlignment,
  OutOfMemory
}
 Allocation results. More...
 
typedef struct Allocator::Range Range
 Describes a range of memory. More...
 
- Static Public Member Functions inherited from Allocator
static void setDefault (Allocator *alloc)
 Makes the given Allocator the default. More...
 
static AllocatorgetDefault ()
 Retrieve the currently default Allocator. More...
 
- Protected Member Functions inherited from Allocator
Address aligned (const Address addr, const Size boundary) const
 Align memory address. More...
 

Detailed Description

Allocates virtual memory using the memory server.

Definition at line 36 of file PageAllocator.h.

Constructor & Destructor Documentation

◆ PageAllocator()

PageAllocator::PageAllocator ( const Range  range)

Class constructor.

Parameters
rangeBlock of continguous memory to be managed.

Definition at line 21 of file PageAllocator.cpp.

Member Function Documentation

◆ allocate()

Allocator::Result PageAllocator::allocate ( Allocator::Range args)
virtual

Allocate memory.

Parameters
argsContains the requested size and alignment on input. On output, contains the actual allocated address.
Returns
Result value.

Reimplemented from Allocator.

Definition at line 32 of file PageAllocator.cpp.

References Memory::Range::access, Allocator::Range::address, Allocator::aligned(), Allocator::base(), ERROR, m_allocated, MapSparse, MinimumAllocationSize, Allocator::OutOfMemory, PAGESIZE, Memory::Range::phys, MemoryMap::range(), Memory::Readable, SELF, Memory::Range::size, Allocator::Range::size, Allocator::Success, API::Success, Memory::User, MemoryMap::UserHeap, Memory::Range::virt, VMCtl(), Memory::Writable, and ZERO.

◆ available()

Size PageAllocator::available ( ) const
virtual

Get memory available.

Returns
Size of memory available by the Allocator.

Reimplemented from Allocator.

Definition at line 27 of file PageAllocator.cpp.

References m_allocated, and Allocator::size().

◆ release()

Allocator::Result PageAllocator::release ( const Address  addr)
virtual

Release memory.

Parameters
addrPoints to memory previously returned by allocate().
Returns
Result value.
See also
allocate
Todo:
Currently this function does not actually release memory back to the system. A potential problem with the current implementation is that releasing memory may result in fragmented virtual memory that may break higher-level allocators.

Reimplemented from Allocator.

Definition at line 73 of file PageAllocator.cpp.

References Allocator::InvalidAddress.

Field Documentation

◆ m_allocated

Size PageAllocator::m_allocated
private

Total number of bytes allocated.

Definition at line 87 of file PageAllocator.h.

Referenced by allocate(), and available().

◆ MinimumAllocationSize

const Size PageAllocator::MinimumAllocationSize = PAGESIZE * 32U
staticprivate

Minimum size required for allocations.

Definition at line 41 of file PageAllocator.h.

Referenced by allocate().


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