modm API documentation
modm::BlockAllocator< T, BLOCK_SIZE > Class Template Reference

#include <modm/driver/storage/block_allocator.hpp>

Public Member Functions

void initialize (void *heapStart, void *heapEnd)
 
void * allocate (std::size_t requestedSize)
 Allocate memory.
 
void free (void *ptr)
 
std::size_t getAvailableSize () const
 

Detailed Description

template<typename T, unsigned int BLOCK_SIZE>
class modm::BlockAllocator< T, BLOCK_SIZE >

Memory allocator.

Template Parameters
BLOCK_SIZESize of one allocatable block in words (sizeof(T) bytes) (BLOCKSIZE * sizeof(T) * n) - 4 has to be dividable by 4 for every n
Author
Fabian Greif

Member Function Documentation

template<typename T , unsigned int BLOCK_SIZE>
void modm::BlockAllocator< T, BLOCK_SIZE >::free ( void *  ptr)

Free memory in O(1)

Parameters
ptrMust be the same pointer previously acquired by allocate().
template<typename T , unsigned int BLOCK_SIZE>
void modm::BlockAllocator< T, BLOCK_SIZE >::initialize ( void *  heapStart,
void *  heapEnd 
)

Initialize the raw memory.

Needs to called before any calls to allocate() or free(). Must be called only once!

Parameters
heapStartNeeds to point to the first available byte
heapEndNeeds to point directly above the last available memory position.

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