2011-06-19 12 views
2

私は現在カスタムアロケータを試しています。メモリプールでカスタムアロケータを実装するsmall applicationがあります。std :: set <T>をメモリプールに接続

それはstd::vectorで動作しますが、私はstd::setでそれをしようとしたとき、私はランタイムエラーを取得:

typedef std::set<Data, std::less<Data>, my_allocator<Data> > PoolSet; 

Pool<Data> pool(1024);  
PoolSet set; 
set.insert(Data()); // error: no pool found for type: std::_Rb_tree_node<Data> 

問題がのstd ::セットは、データとデータノードの両方のための私のアロケータを使用していることです。データノードに登録されたプールがないため、コードは失敗します。

詳細は、codeに記載されています。

私はこれを回避するために何をしているのですか?

+0

あなたは、プールされるマップの内部データ構造を欠けていますか?そうでなければ 'std :: allocator'を返すような方法で' my_allocator :: rebind'を定義することができます。 –

答えて

1

これは@BenVoigtに記載されているrebindです。

http://en.wikipedia.org/wiki/Allocator_(C++)

Allocators are required to supply a template class member template <typename U> struct A::rebind { typedef A<U> other; }; , which enables the possibility of obtaining a related allocator, parametrized in terms of a different type. For example, given an allocator type IntAllocator for objects of type int , a related allocator type for objects of type long could be obtained using IntAllocator::rebind<long>::other .

関連する問題