cacay / memorypool Goto Github PK
View Code? Open in Web Editor NEWAn easy to use and efficient memory pool allocator written in C++.
Home Page: http://www.coskuacay.com
An easy to use and efficient memory pool allocator written in C++.
Home Page: http://www.coskuacay.com
Hi,
I was reading the testcases and something that piqued my curiosity greatly was a mention that MemoryPool would be really useful with multiple linked lists. I'd really love to see an example; could you write one up? My own knowledge of implementing algorithms would really benefit. :)
Thanks for your time,
Colin
hello There's a question I'd like to ask.
template <typename T, size_t BlockSize>
MemoryPool<T, BlockSize>::~MemoryPool()
noexcept
{
slot_pointer_ curr = currentBlock_;
while (curr != nullptr) {
slot_pointer_ prev = curr->next;
operator delete(reinterpret_cast<void*>(curr));
curr = prev;
}
}
currentBlock_ is not operator new(BlockSize) return address. If there are multiple blocks, MemoryPool destroy Unable to release memory.
I think we need to add a linked list record operator new(BlockSize) address
When compiling with the highest warning level -Wall -Werror -Wextra
I receive these error messages regarding unused variables.
May be in the next release you could add this code in order it does not fail when using the very aggressive compiler flags:
(void) variable-name;
The author apparently does not appreciate any response because old issue entries do not have any comment. I wrote my own memory pool which can be at least compiled in a professional environment...
C-11/MemoryPool.h should include type_traits and utility as it depend on them.
Hi,
I want to use the pool allocator for thousands of small arrays:
typedef uint16_t elementType;
typedef elementType* arrayP;
typedef elementType array_2[2];
MemoryPool<array_2> mMemPool_2;
arrayP foo;
foo = reinterpret_cast<elementType(*)>(mMemPool_2->newElement());
...
mMemPool_2->deleteElement(reinterpret_cast<array_2(*)>(foo));
(the recast I do because I need always foo-like elements because I put the pointers in a hashmap, I take care of the size of the array myself, i.e. I store the length at[0])
With that I always get an compile error in the deleteElement function. When I comment out the call to the destructor (placement new destructor?) it works.
template <typename T, size_t BlockSize>
inline void MemoryPool<T, BlockSize>::deleteElement(pointer p) {
if (p != nullptr) {
// p->~value_type();
deallocate(p);
}
}
Why is that and is it correct in my special case?
Thanks!
steffen
the compile error (gcc 4.8.1):
MemoryPool.tcc: In instantiation of ‘void MemoryPool<T, BlockSize>::deleteElement(MemoryPool<T, BlockSize>::pointer) [with T = short unsigned int [2]; long unsigned int BlockSize = 1966080ul; MemoryPool<T, BlockSize>::pointer = short unsigned int ()[2]]’:
MinHashEncoder.h:310:84: required from here
MemoryPool.tcc:228:4: error: request for member ‘~MemoryPool<short unsigned int [2], 1966080ul>::value_type’ in ‘ p’, which is of non-class type ‘short unsigned int [2]’
p->~value_type();
I might be wrong but shouldn't
MemoryPool/C-11/MemoryPool.tcc
Line 104 in 1ab4683
be
operator delete(reinterpret_cast<void*>(curr), BlockSize);
to delete the whole block?
I understand that this repo is no longer being maintained. I was searching through GitHub for C++ memory pool implementations. I believe that this is effectively a copy of yours, but with the license headers removed.
I created an issue on his repo as well.
#include "../src/memory_pool.h"
// #include "../tmp/MemoryPool.h"
// #include "../src/allocate.h"
#include <vector>
#include <cstdlib>
#include <iostream>
std::vector<int, MemoryPool<int>> v;
// std::vector<int> v;
int main(void) {
for (int i=0; i<100000000; i++) {
int t = rand()%10;
v.emplace_back(t);
if (i % 100000 == 0)
std::cout << i << "\n";
}
return 0;
}
0
100000
200000
300000
400000
500000
600000
700000
800000
900000
1000000
1100000
1200000
1300000
1400000
1500000
1600000
1700000
1800000
1900000
2000000
[1] 95072 segmentation fault ./test
when i use the padding function from this code,i found that the summary of address and padding mod align bytes cant be zero sometimes.Should it be a problem? I google the padding problem,someone say the padding function should be like this:
inline size_t padding(int* p, size_t align) noexcept
{
uintptr_t result = reinterpret_cast<uintptr_t>(p);
return ((align - (result%align)) % align);
}`
I make a few tests,it works
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.