1 #ifndef __JLANG__JALLOCATOR__
2 #define __JLANG__JALLOCATOR__
16 namespace JPP {
using namespace JLANG; }
40 buffer =
new unsigned char[block_size * number_of_blocks];
43 THROW(
JException,
"JAllocatorBuffer::init(): not enough space in memory.");
50 for (
JBlock_t i = 0;
i != number_of_blocks; p += block_size) {
65 inline void*
allocate(
const std::size_t block_size)
83 void free(
void* p,
const std::size_t block_size)
85 unsigned char* q =
static_cast<unsigned char*
>(p);
96 THROW(
JException,
"JAllocatorBuffer::free(): failed truncation check.");
137 const JBlock_t number_of_blocks = std::numeric_limits<JBlock_t>::max()) :
166 for (const_iterator
i = this->begin();
i != this->end(); ++
i) {
167 n +=
i->numberOfFreeBlocks;
183 for (iterator
i = this->begin(); ; ++
i) {
185 if (
i == this->end()) {
194 if (
i->numberOfFreeBlocks != 0) {
221 if (this->size() != 1) {
223 if (p < pDealloc->buffer ||
228 if (p >=
i->buffer &&
251 if (i != this->rend()) {
253 delete [] this->rbegin()->buffer;
long long int getFreeRAM()
Get total free RAM.
JAllocatorBuffer * pDealloc
JAllocator(const std::size_t block_size, const JBlock_t number_of_blocks=std::numeric_limits< JBlock_t >::max())
Constructor.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
JBlock_t numberOfFreeBlocks
JAllocatorBuffer * pAlloc
JAllocatorBuffer::JBlock_t JBlock_t
void free(void *p, const std::size_t block_size)
Deallocate memory.
Low-level memory management.
JAllocatorBuffer(const std::size_t block_size, const JBlock_t number_of_blocks)
Constructor.
long long int getTotalRAM()
Get total used RAM.
void free(void *p)
Deallocate memory.
void * allocate(const std::size_t block_size)
Allocate memory.
Memory management for small objects.
JBlock_t firstAvailableBlock
void * allocate()
Allocate memory.