LoginSignup
1
1

More than 3 years have passed since last update.

C++ Builder XE4, 10.2 Tokyo > TMemo > TStringList型のリストをTMemoに割当てる実装 > TMemo.Assign()など | link:パフォーマンス

Last updated at Posted at 2017-10-17
動作環境
C++ Builder XE4
RAD Studio 10.2 Tokyo Update 2 (追記: 2018/01/05)

特定のフォルダにあるファイルリストを取得する。
その中で、TStringListに取得した文字列リストをTMemoに表示する方法が気になった。

見つけたのはTMemo->Assign()という方法。

使ってみた。

対象ファイル

bash > Brace Expansionで日付のダミーファイルを作る | ファイル名失敗時: MinGW32でファイルを消す
にて作ったファイル。

code

関連: c++ builder / fileIO > 指定日付以降のファイルだけ見つける

Unit1.cpp
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include <IOUtils.hpp>
#include <memory>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------

/*
v0.1 Oct. 17, 2017
  - 対象フォルダにあるファイルリストを取得
*/


String kTargetFolder = L"D:\\WORK\\filedelete_171017";
//String kDueDateTime = L"2017/02/28 12:00";

__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::dbgB_getListClick(TObject *Sender)
{
    String searchPattern = L"*.csv";
    TSearchOption option = TSearchOption::soAllDirectories;

    TStringDynArray fileList = TDirectory::GetFiles(kTargetFolder, searchPattern, option);
    int allcnt = fileList.Length;

    std::unique_ptr<TStringList> lst(new TStringList);

    TDateTime filedt;
    for(int idx = 0; idx < fileList.Length; idx++) {
//      filedt = TFile::GetLastWriteTime(fileList[idx]);
//      if ( filedt < VarToDateTime(kDueDateTime) ) {
//          continue;
//      }
        lst->Add(fileList[idx]);
    }

    String msg = IntToStr(lst->Count) + L"/" + IntToStr(allcnt);
    OutputDebugString(msg.c_str());

    Memo1->Lines->Assign(lst.get()); //********************
}
//---------------------------------------------------------------------------

qiita.png

パフォーマンス

リストに大量のアイテムを高速に登録するには by 山本隆さん

上記において以下の3つの方法の処理時間が比較されている。

  • BeginUpdate, EndUpdate使用
  • Assign使用
  • AddItem使用

Assignが最速ではないが、コードが読みやすいのと、処理速度が許容範囲であると思われる場合はありうる。

1
1
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
1
1