Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem with raw array as value type #2

Open
steffenheyne opened this issue Nov 4, 2015 · 0 comments
Open

problem with raw array as value type #2

steffenheyne opened this issue Nov 4, 2015 · 0 comments

Comments

@steffenheyne
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant