🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #16426

Re: File Copy Operation

#16426
From: Nick B. Cassos
Date: Thu, 15 May 2003 18:03
38 lines
2551 bytes
On Thu, 15 May 2003 14:28:50 +0500, "Muhammad Momin Rashid"
<momin@hotmail.com> wrote:

>1. This approach is significantly slower than the windows file copy
>operation itself.  I need to speed up my file coping operation.

This operation should not be "significantly" slower, however, you must
certainly abandon TFileStream and use Win API (CreateFile, ReadFile,
WriteFile). You gain a little bit of power by bypassing the VCL layer,
but most importantly you are able to use the appropriate flags in
CreateFile such as - for example - the FILE_FLAG_SEQUENTIAL_SCAN flag
in dwFlagsAndAttributes.

The buffer size used in copying is critical. I use a size of 32K as
the best for all purposes.

>2. The operation consumes a lot of processing power while reading from media
>such as CDROM etc.  Is there any way to bring down the processor usage?

The only way is 1) to use a thread, and 2) to take a Sleep() for 0 or
1 ms, after each copyed chunk. This will give you a usage of about 4%
even on old hardware.

>3. If there is a problem in file reading (bad or corrupted media) the system
>locks up for a fair amount of time.  How to avoid this? and how can I
>control the amount of time system has to keep trying before it quits trying
>to read?

In most cases Windows recover. The behaviour varies between versions.
You can't do much about this except for using SetErrorMode with
SEM_FAILCRITICALERRORS especially in case of dealing with removable
media. In any case, the copy is handled by a thread which can send a
periodic signal to your main (UI) thread.


-- 

Nick B. Cassos
Technical Details
Message-ID: <9il7cvo1pgrogm92qjnlmr3065p43vvd6f@4ax.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!newsfeed.news2me.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail
References: <3ec35dd4@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,2c3eb0c8d9515a68
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-05-15 11:13:09 PST
From: Nick B. Cassos <nbc@no_spam.ath.forthnet.gr>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: File Copy Operation
Date: Thu, 15 May 2003 21:03:09 +0300
Message-ID: <9il7cvo1pgrogm92qjnlmr3065p43vvd6f@4ax.com>
References: <3ec35dd4@newsgroups.borland.com>
X-Newsreader: Forte Agent 1.93/32.576 English (American)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 213.16.148.235
X-Trace: newsgroups.borland.com 1053021787 213.16.148.235 (15 May 2003 11:03:07 -0700)
Lines: 38
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!newsfeed.news2me.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail