2

C++ プロジェクトでメモリの断片化の問題が発生し、次のことを試みました。

  1. nedmalloc - ストレス テストに合格しませんでした (15 時間後にクラッシュしました)。つまり、ほとんどの場合は機能しますが、すべてではありません。また、他のアロケータよりもメモリ使用量が多くなります。

  2. jemalloc- Windows の準備ができていませんか?

  3. tcmalloc - 静的リンクを使用してホスト コードでコンパイルされますが、CRT シンボルと競合します。tc_malloc(...) のようなエイリアスを使用して、割り当て用の独自のラッパーを作成できますか? どうやってするか?

コメントはありますか?前もって感謝します。

4

4 に答える 4

1

プログラムの開始時にこの APIを使用して、Windows Low Fragmentation Heap (LFH) を使用するようにプロジェクトを設定します。これにより、カスタム実装でこれ以上作業しなくても問題が解決する場合があります。

MSDN から直接取得したサンプル コード:

#include <windows.h>
#include <tchar.h>
#include <stdio.h>

#define HEAP_LFH 2

int __cdecl _tmain()
{
    BOOL bResult;
    HANDLE hHeap;
    ULONG HeapInformation;

    // 
    // Note: The HeapSetInformation function is available on Windows 2000 with SP4
    // only if hotfix KB 816542 is installed. To run this example on Windows 2000,
    // use GetProcAddress to get a pointer to the function if available.
    //

    //
    // Enable heap terminate-on-corruption. 
    // A correct application can continue to run even if this call fails, 
    // so it is safe to ignore the return value and call the function as follows:
    // (void)HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0);
    // If the application requires heap terminate-on-corruption to be enabled, 
    // check the return value and exit on failure as shown in this example.
    //
    bResult = HeapSetInformation(NULL,
                                 HeapEnableTerminationOnCorruption,
                                 NULL,
                                 0);

    if (bResult != FALSE) {
        _tprintf(TEXT("Heap terminate-on-corruption has been enabled.\n"));
    }
    else {
        _tprintf(TEXT("Failed to enable heap terminate-on-corruption with LastError %d.\n"),
                 GetLastError());
        return 1;
    }

    //
    // Create a new heap with default parameters.
    //
    hHeap = HeapCreate(0, 0, 0);
    if (hHeap == NULL) {
        _tprintf(TEXT("Failed to create a new heap with LastError %d.\n"),
                 GetLastError());
        return 1;
    }

    //
    // Enable the low-fragmenation heap (LFH). Starting with Windows Vista, 
    // the LFH is enabled by default but this call does not cause an error.
    //
    HeapInformation = HEAP_LFH;
    bResult = HeapSetInformation(hHeap,
                                 HeapCompatibilityInformation,
                                 &HeapInformation,
                                 sizeof(HeapInformation));
    if (bResult != FALSE) {
        _tprintf(TEXT("The low-fragmentation heap has been enabled.\n"));
    }
    else {
        _tprintf(TEXT("Failed to enable the low-fragmentation heap with LastError %d.\n"),
                 GetLastError());
        return 1;
    }

    return 0;
}
于 2010-09-28T11:13:52.137 に答える
0

doug lea の malloc (dlmalloc)hordeアロケーターなど、他にもいくつかのアロケーターが利用可能です。


nedmalloc - ストレス テストに合格しませんでした (15 時間後にクラッシュしました)。つまり、ほとんどの場合は機能しますが、すべてではありません。

放棄する前に最初にクラッシュした場所と理由を追跡できるかどうかを確認してください。それはあなたの側からのエラーである可能性があります。また、ned の SVN リポジトリを確認してください。問題の修正が既にある可能性があります。

tcmalloc - 静的リンクを使用してホスト コードでコンパイルされますが、CRT シンボルと競合します。tc_malloc(...) のようなエイリアスを使用して、割り当て用の独自のラッパーを作成できますか? どうやってするか?

CRTシンボルをそのままにしておくのが最善だと思います(念のため)ので、先に進んでプロジェクトを編集して、競合するシンボルが代わりに希望する規則に従うようにします(結局、理由でソースがあります)

于 2010-09-28T09:30:43.197 に答える
0

Intel の TBB は、動作するアロケーターを提供します。 http://threadingbuildingblocks.org/download.php

于 2011-07-07T21:10:58.620 に答える