0
0

More than 5 years have passed since last update.

c++ builder > アプリ使用メモリの確認 > 失敗編

Last updated at Posted at 2016-08-18
動作環境
C++ Builder XE4

失敗編1

FastMMでメモリリークを調査中だが、Logを見ても特定が難しくなってきた。
ソースを全部読みながら静的解析になるだろうか。

実行中のアプリのメモリ使用量はタスクマネージャで確認できるが、任意の時間でのメモリ使用量を取得したくなった。

stackoverflowのapenwarrによる回答にDelphi実装でのメモリ確認コードがあった。

C++ Builderに組み替えてみた。

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    TMemoryManagerState st;

    GetMemoryManagerState(st);
    int result = st.TotalAllocatedMediumBlockSize + st.TotalAllocatedLargeBlockSize;

    int sbtsize = st.SmallBlockTypeStates.Size();
    TSmallBlockTypeState sb;
    for(int idx=0; idx < sbtsize; idx++) {
        sb = st.SmallBlockTypeStates[idx];
        result = result + sb.UseableBlockSize * sb.AllocatedBlockCount;
    }

    ShowMessage(IntToStr(result));
}

delphiでのforイテレータの使用はC++ Builderではそのまま使えなかったと思うので、上記のようなfor()文に変更した。

実行したところ、メモリ使用量は0になった(タスクマネージャで確認したところ2208K使用)。
インスペクタで確認したところsb.AllocatedBlockCountなどが0になっている。
sb.UseableBlockSize などには数値が入っている。

apenwarrの回答に対する以下のコメントと関係があるのかどうか。

besides the above, this method shows the amount of memory allocated by the application, not the amount of memory used by it

失敗編2

同じstackoverflowのリンクのJim McKeethによるDelphiコードをC++ Builder実装しようとしたが、psAPIをincludeしてもTProcessMemoryCounters型などが見つからなかった。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0