Skip to content

problem with raw array as value type #2

@steffenheyne

Description

@steffenheyne

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions