Macaulay2 Engine
Loading...
Searching...
No Matches
allocator.hpp
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#ifndef BIBASIS_FAST_ALLOCATOR_HPP
11#define BIBASIS_FAST_ALLOCATOR_HPP
12
39
40namespace BIBasis
41{
57 {
58 private:
59 const size_t MemoryPageSize;
60 const size_t TSize;
61 const size_t PageSize;
62 void** FreeBlock;
63
64 public:
65 FastAllocator(const size_t blockSize);
67
68 void* Allocate();
69 void Free(void* pointer);
70
71 private:
72 void ExpandMemory();
73 };
74
76 {
77 if (!FreeBlock)
78 {
80 }
81
82 void* pointer = static_cast<void*>(FreeBlock);
83 FreeBlock = static_cast<void**>(*FreeBlock);
84 return pointer;
85 }
86
87 inline void FastAllocator::Free(void* pointer)
88 {
89 *(static_cast<void***>(pointer)) = FreeBlock;
90 FreeBlock = static_cast<void**>(pointer);
91 }
92}
93
94#endif // BIBASIS_FAST_ALLOCATOR_HPP
const size_t MemoryPageSize
Definition allocator.hpp:59
FastAllocator(const size_t blockSize)
Definition allocator.cpp:22
void Free(void *pointer)
Definition allocator.hpp:87
const size_t PageSize
Definition allocator.hpp:61