Macaulay2 Engine
Loading...
Searching...
No Matches
allocator.cpp
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright (C) 2006-2011 by Mikhail V. Zinin *
3 * mzinin@gmail.com *
4 * *
5 * You may redistribute this file under the terms of the GNU General *
6 * Public License as published by the Free Software Foundation, either *
7 * version 2 of the License, or any later version. *
8 *****************************************************************************/
9
10#include <cstdlib>
11#include <cmath>
12#include <string>
13
14#include "allocator.hpp"
15#include "error.h"
16
17#define int_divide_ceil(x,y) (((x)+(y)-1)/(y))
18#define int_divide_floor(x,y) ((x)/(y))
19
20namespace BIBasis
21{
23 : MemoryPageSize(1048576)
24 , TSize(int_divide_ceil(blockSize,sizeof(void*)))
26 , FreeBlock(nullptr)
27 {
28 }
29
33
35 {
36 void **begin = static_cast<void**>(malloc(MemoryPageSize)),
37 **end = begin + TSize * (PageSize - 1),
38 **tmp;
39
40 if (!begin)
41 {
42 throw std::string("BIB::FastAllocator::ExpandMemory(): failed to allocate memory.");
43 }
44
45 *(reinterpret_cast<void***>(end)) = FreeBlock;
46 FreeBlock = static_cast<void**>(begin);
47 do
48 {
49 tmp = begin + TSize;
50 *(reinterpret_cast<void***>(begin)) = tmp;
51 begin = tmp;
52 } while(begin < end);
53 }
54}
#define int_divide_ceil(x, y)
Definition allocator.cpp:17
#define int_divide_floor(x, y)
Definition allocator.cpp:18
BIBasis::FastAllocator — per-size-class slab allocator for BIBasis's small objects.
const size_t MemoryPageSize
Definition allocator.hpp:59
FastAllocator(const size_t blockSize)
Definition allocator.cpp:22
const size_t PageSize
Definition allocator.hpp:61
Engine error-reporting primitives: ERROR, INTERNAL_ERROR, error, error_message.
TermIterator< Nterm > begin(Nterm *ptr)
Definition ringelem.cpp:4
TermIterator< Nterm > end(Nterm *)
Definition ringelem.cpp:5