任何人对C/c ++的无锁内存分配器有什么好的经验?
我已经研究了boost和libcds,但我不确定要使用哪个库.
背景,我一直在研究"无锁,无等待,无阻塞,动态完美哈希,可扩展,并发哈希表"*是的我知道这听起来很自命不凡,但这就是所谓的.
无论如何,我正准备开始多线程测试,并且我需要在添加新节点时找出设置内存分配的最佳方法.(当我需要分配指针数组时)
那么有没有人有无锁内存分配的任何良好经验?
我正在实现tbb的并发哈希映射,以将其性能与一组其他并发哈希表进行比较.
然而,我从中获得的性能是可怕的,我无法相信它与其他并发哈希表相比是那么慢
这是我的实现:
class TBB: public TestDs{
typedef tbb::concurrent_hash_map<int,int, HashCompare<int> > hash_t;
private:
hash_t _ds;
public:
TBB(const Configuration& config) : _ds(config.initial_count) {
}
bool containsKey(int key) {
hash_t::accessor a;
if(_ds.find(a,key)){
return true;
}
else
return false;
}
int get(int key) {
hash_t::accessor a;
if(_ds.find(a,key)){
return (int)(a->second);
}
else
return 0;
}
int put(int key, int value) {
return _ds.insert( std::make_pair(key, value) );
}
int remove(int key) {
return _ds.erase(key);
}
int size() {
return _ds.size();
}
const char* name() { …Run Code Online (Sandbox Code Playgroud) 我正在使用libcds,他们有Michael Hash Map和Split order list的实现.
基于我从文档中收集的信息,我是如何实现它们的:
包括:
#include <cds/map/michael_hash_map.h>
#include <cds/map/split_ordered_list.h>
using namespace cds;
Run Code Online (Sandbox Code Playgroud)
码:
class TestDs {
public:
virtual bool containsKey(int key)=0;
virtual int get(int key)=0;
virtual int put(int key, int value)=0;
virtual int remove(int key)=0;
virtual int size()=0;
virtual const char* name()=0;
virtual void print()=0;
virtual void shutdown()=0;
};
Run Code Online (Sandbox Code Playgroud)
码:
class Michael: public TestDs{
private:
cds::map::MichaelHashMap<int,int,cds::map::pair_traits <int, int>, cds::map::type_traits, CDS_DEFAULT_ALLOCATOR> _ds;
public:
Michael(const Configuration& config) : _ds(config.initial_count,config.load_factor) {
}
bool containsKey(int key) {
return (_ds.find(key)!=0);
} …Run Code Online (Sandbox Code Playgroud)