Allocating Concurrent Hash Map on Shared memory
- Dominant language
- C++
- Stars
- 30.5k
- Forks
- 5.9k
- PR merge metrics
- No merged PRs in 30d
Description
I'm trying to allocate Concurrent Hash Map on Shared Memory using Boost shared memory allocator
```c++
#include
#include
#include
template
using ShmAlloc = boost::interprocess::allocator;
using Key = int;
using Value = int;
using Table = folly::ConcurrentHashMap, std::equal_to, ShmAlloc>;
int main()
{
//Create a new segment with given name and size
managed_shared_memory segment(create_only, "SharedTable", 65536);
//Initialize shared memory STL-compatible allocator
ShmAlloc alloc_inst (segment.get_segment_manager());
Table* table = segment.construct("t1")(alloc_inst);
// In another process I want to find it
auto res = segment.find("t1");
Table* found_table = res.first;
}
```
but I got following error:
```
ConcurrentHashMap.h:496:74: error: no matching function for call to ‘boost::interprocess::allocator, boost::interprocess::iset_index> >::allocator()’
SegmentT* newseg = (SegmentT*)Allocator().allocate(sizeof(SegmentT));
```
I tried to wrap Boost shared memory allocator with an allocator that has a default constructor and a static member that stores the Boost shared memory instance. This resolves the compilation error but the serious following problem rises: The segmentation fault occurs due to the fact that **Concurrent Hash Map is not using Allocator::pointer (_an offset_ptr when using Boost allocator_)**.
Can anyone help me?
Contributor guide
Assessment
This issue has not been assessed yet.