2017-08-04 12 views
0

私はデータを見つけるか、調べるのは簡単であるべき次の2つの理由、unordered_multisetのメモリ消費量を減らすには?

  1. で私のコードでunordered_multisetを使用。
  2. 重複する値を読み込むためのサポートが必要です。

unordered_multisetは通常&ベクトル、両方の挿入のためのルックアップのためのマルチセットよりもはるかに速く、時には削除するためのものです。

しかし、悪いことに、あまりにも多くのメモリが必要です。

私はunsigned __int64(8バイト)の値をunordered_multisetに格納し、unordered_multisetから値を適切にクリアしました。 あなたは誰でも説明することができます、なぜそのメモリを取る&どのようにこのメモリ消費を解決するには?

+4

どのようにしてメモリ消費量を測定しましたか? – Drek

+0

@Drekタスクマネージャからメモリ消費量の詳細を取得しました。私は私のアプリケーションのプロセスIDを使用してそれを見つける。 – Durai

+2

いくつかの*別個のアイテムをいくつ挿入しますか?一度すべての値が挿入されると、 'unordered_multiset'のメモリフットプリントの大きさはどれくらいですか? – dasblinkenlight

答えて

0

std::コンテナが使用するスペースの量をより正確に測定できるようにするには、割り振る量を記録するカスタムアロケータを提供します。

std::size_t total_allocation = 0; 

template< class T > 
struct logging_allocator 
{ 
    using value_type = T; 
    using pointer = T*; 
    using const_pointer = const T*; 
    using reference = T&; 
    using const_reference = const T&; 
    using size_type = std::size_t; 
    using difference_type = std::ptrdiff_t; 
    using propagate_on_container_move_assignment = std::true_type; 
    template< class U > struct rebind { using other = logging_allocator<U>; }; 
    using is_always_equal = std::true_type; 

    pointer address(reference x) const { return base.address(x); } 
    const_pointer address(const_reference x) const{ return base.address(x); } 

    pointer allocate(size_type n, const_pointer hint = nullptr){ 
     total_allocation += n; 
     return base.allocate(n, hint); 
    } 
    pointer allocate(size_type n, const void * hint){ 
     total_allocation += n; 
     return base.allocate(n, hint); 
    } 
    pointer allocate(size_type n){ 
     total_allocation += n; 
     return base.allocate(n, hint); 
    } 

    void deallocate(T* p, size_type n) { 
     total_allocation -= n; 
     return base.deallocate(p, n); 
    } 

    size_type max_size() const { 
     return base.max_size(); 
    } 

    void construct(pointer p, const_reference val) { 
     total_allocation += sizeof(T); 
     return base.construct(p, val); 
    } 
    template< class U, class... Args > 
    void construct(U* p, Args&&... args) { 
     total_allocation += sizeof(U); 
     return base.construct(p, args...); 
    } 

    void destroy(pointer p) { 
     total_allocation -= sizeof(T); 
     return base.destroy(p); 
    } 
    template< class U > 
    void destroy(U* p) { 
     total_allocation -= sizeof(U); 
     return base.destroy(p); 
    } 

private: 
    std::allocator<T> base; 
} 
0

Calethは良い提案を持っている、あるいはあなたがマルチセットにし、後に挿入する直前にmemory usage within processes

で見ることができます。

ほとんどの場合、巨大なdllが読み込まれます。

関連する問題