0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

c++ builder / fileIO > TFile::Copy() > 大きいファイルのコピー時 > 「5秒以上の応答なし」の確認

Last updated at Posted at 2016-07-13
動作確認
C++ Builder XE4
Windows 7pro (3GB メモリ割当)

TFile::Copy()関連の情報を見ている中で以下を見つけた。

DelphiでファイルをコピーするときはWin32APIのCopyFile関数 (en)か、これをラッピングした(System.)IOUtilsのTFile.Copyなどを使うのが普通ですが、大きめのファイルだったり遅いデバイスだったり、あるいはその両方で、ファイルコピーに5秒以上かかるとWindowsに"応答なし"と判断されてしまうことになります。

上記の情報は(おそらく)DelphiXE3で動かしたのだと思われる。

こちらの環境(C++ Builder XE4)で応答なしになるか確認した。

コピーするファイルは現在セットアップ作業に使っている以下のファイル(3.6GB)を用いた。
http://ftp.riken.jp/Linux/centos/6/isos/x86_64/
のCentOS-6.8-x86_64-bin-DVD1.iso

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

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

# include <vcl.h>
# pragma hdrstop

# include <IOUtils.hpp>
# include "Unit1.h"
//---------------------------------------------------------------------------
# pragma package(smart_init)
# pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
	String from = L"D:\\TestData\\160713_FROM\\CentOS-6.8-x86_64-bin-DVD1.iso";
	String to = L"D:\\TestData\\160713_TO\\CentOS-6.8-x86_64-bin-DVD1.iso";

	try {
      	TFile::Copy(from, to, /* overwrite=*/true);
	} catch (...) {
		int nop1 = 1;
	}
	int nop2 = 1;
}
//---------------------------------------------------------------------------

上記の動作で確認したかったことは「5秒以上の応答なし」の時にtry, catchでエラーとなるか、ということだった。

実際に動かしたところ、try, catchでのエラーは発生しなかった。
一方で、メインウィンドウの表示がコピー中は更新されなかったため、こちらが「5秒以上の応答なし」に対応するのかもしれない。

ファイルコピー自体は90秒程度かかった。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?