Code Monkey home page Code Monkey logo

memorypool's People

Contributors

cacay avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

memorypool's Issues

Possible license violation?

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.

problem with raw array as value type

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();

unused variabled

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...

Add example about multiple linked lists

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

padding function

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

[Fatal Error] When the amount of data is too large, errors occur

#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

image

Missing includes

C-11/MemoryPool.h should include type_traits and utility as it depend on them.

MemoryPool destroy problem

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.