LoginSignup
0
0

More than 5 years have passed since last update.

c++ builder XE4 > TeeChart > AddXY() とDelete()の繰り返し > メモリ使用量の変化調査

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

関連 http://qiita.com/7of9/items/973ecac73c16b0740e36

TeeChartのSeriesのAddXY()をして、余分なデータをDelete()する、という処理を繰り返した時にメモリリークが発生しないか調べた。

Unit1.h
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <VCLTee.Chart.hpp>
#include <VCLTee.Series.hpp>
#include <VCLTee.TeEngine.hpp>
#include <VCLTee.TeeProcs.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:    // IDE で管理されるコンポーネント
    TChart *Chart1;
    TFastLineSeries *Series1;
    TButton *Button1;
    void __fastcall FormShow(TObject *Sender);
    void __fastcall Button1Click(TObject *Sender);
private:    // ユーザー宣言
    void __fastcall addData();
    void __fastcall removeData();
public:     // ユーザー宣言
    __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
Unit1.cpp
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include <DateUtils.hpp>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------

static const int kNumData = 200000;

void __fastcall TForm1::FormShow(TObject *Sender)
{
    Chart1->Series[0]->XValues->DateTime = true;
    Chart1->BottomAxis->DateTimeFormat = L"nn:ss";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::addData()
{
    TDateTime dt;

    dt = Now();

    double yval;

    for (int idx=0; idx < kNumData; idx++) {
        yval = (1+ idx) % 2;
        Series1->AddXY(dt, yval, "", clRed);
        dt = IncSecond(dt, 1);
    }
}

void __fastcall TForm1::removeData()
{
    for (int idx=0; idx < kNumData; idx++) {
        if (Series1->Count() == 0) {
            break;
        }
        Series1->Delete(0);
    }
}

//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    Screen->Cursor = crHourGlass;

    removeData();
    addData();

    Screen->Cursor = crArrow;
}
//---------------------------------------------------------------------------

qiita.png

TeeChartで使えるデー多数は20万件なので、20万件のデータをremove, addしてみた。

メモリリークしてなかった。8332KBから変化なし。

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