从CD复制文件时,如何防止CPU使用率增加到100%? [英] How can I prevent CPU Usage increasing to 100 percent when copying files from CD?

查看:98
本文介绍了从CD复制文件时,如何防止CPU使用率增加到100%?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VB6中编写了一个简单的程序,将所有文件从CD-ROM上的目录

复制到我的硬盘上。大约有10个文件,每个大约

30MB。


该程序使用Get和Put将数据从CD中提取到缓冲区中
然后将
放入磁盘。见下面的代码。它可以正常工作,但在复制所有文件之前它会大幅减速。 Windows任务管理器

显示复制文件时CPU使用率逐渐增加,直到大约6个文件达到100%后,才会显示
。那就是它什么时候开始变慢。


如何防止CPU使用量增加?这是

代码的内容。所有这些都在另一个循环中,遍历所有文件

in sCDPath with Dir $。我已经尝试过50000到2美元的缓冲区大小,没有区别。


iCDFN = FreeFile

打开sCDPath &安培;用于二进制访问的sFileName读取为#iCDFN

iDiskFN = FreeFile

打开sDiskPath&用于二进制访问的sFileName写为#iDiskFN

Do

如果lStartPos + lIncrement> lFileLen然后_

lIncrement = lFileLen - lStartPos + 1

sBuffer = String(lIncrement,"")

获取#iCDFN ,, sBuffer

把#iDiskFN ,,, sBuffer

lStartPos = lStartPos + lIncrement

如果lStartPos> lFileLen然后退出Do

循环

关闭iCDFN

关闭iDiskFN


TIA - Bryan Rickard

I wrote a simple program in VB6 to copy all the files from a directory
on a CD-ROM to my hard disk. There are about 10 files, each about
30MB.

The program uses Get and Put to get data from the CD into a buffer and
then put it into the disk. See code below. It works, but it slows
down drastically before it copies all the files. Windows Task Manager
shows the CPU usage gradually increasing as the files are copied,
until it reaches 100 percent after about 6 files. That''s when it
starts to get slow.

How can I prevent the CPU usage increasing? Here''s the guts of the
code. All this is within another loop that goes through all the files
in sCDPath with Dir$. I''ve tried buffer sizes from 50000 to 2
million, makes no difference.

iCDFN = FreeFile
Open sCDPath & sFileName For Binary Access Read As #iCDFN
iDiskFN = FreeFile
Open sDiskPath & sFileName For Binary Access Write As #iDiskFN
Do
If lStartPos + lIncrement > lFileLen Then _
lIncrement = lFileLen - lStartPos + 1
sBuffer = String(lIncrement, " ")
Get #iCDFN, , sBuffer
Put #iDiskFN, , sBuffer
lStartPos = lStartPos + lIncrement
If lStartPos > lFileLen Then Exit Do
Loop
Close iCDFN
Close iDiskFN

TIA - Bryan Rickard

推荐答案

。我已经尝试过50000到2美元的缓冲区大小,没有区别。


iCDFN = FreeFile

打开sCDPath &安培;用于二进制访问的sFileName读取为#iCDFN

iDiskFN = FreeFile

打开sDiskPath&用于二进制访问的sFileName写为#iDiskFN

Do

如果lStartPos + lIncrement> lFileLen然后_

lIncrement = lFileLen - lStartPos + 1

sBuffer = String(lIncrement,"")

获取#iCDFN ,, sBuffer

把#iDiskFN ,,, sBuffer

lStartPos = lStartPos + lIncrement

如果lStartPos> lFileLen然后退出Do

循环

关闭iCDFN

关闭iDiskFN


TIA - Bryan Rickard
. I''ve tried buffer sizes from 50000 to 2
million, makes no difference.

iCDFN = FreeFile
Open sCDPath & sFileName For Binary Access Read As #iCDFN
iDiskFN = FreeFile
Open sDiskPath & sFileName For Binary Access Write As #iDiskFN
Do
If lStartPos + lIncrement > lFileLen Then _
lIncrement = lFileLen - lStartPos + 1
sBuffer = String(lIncrement, " ")
Get #iCDFN, , sBuffer
Put #iDiskFN, , sBuffer
lStartPos = lStartPos + lIncrement
If lStartPos > lFileLen Then Exit Do
Loop
Close iCDFN
Close iDiskFN

TIA - Bryan Rickard


2004年1月7日18:06:29 -0800, bw*@unicon.com (Bryan Rickard)写道:
On 7 Jan 2004 18:06:29 -0800, bw*@unicon.com (Bryan Rickard) wrote:
我在VB6中编写了一个简单的程序,将所有文件从CD-ROM上的目录复制到我的硬盘上。大约有10个文件,每个大约有30MB。

程序使用Get和Put将CD中的数据放入缓冲区然后将其放入磁盘。见下面的代码。它有效,但在复制所有文件之前它会大幅减速。 Windows任务管理器
显示随着文件复制,CPU使用率逐渐增加,直到大约6个文件后达到100%。这就是它开始变慢的时候。
I wrote a simple program in VB6 to copy all the files from a directory
on a CD-ROM to my hard disk. There are about 10 files, each about
30MB.

The program uses Get and Put to get data from the CD into a buffer and
then put it into the disk. See code below. It works, but it slows
down drastically before it copies all the files. Windows Task Manager
shows the CPU usage gradually increasing as the files are copied,
until it reaches 100 percent after about 6 files. That''s when it
starts to get slow.




< snip>


究竟是什么慢吗?


你正在做很多工作

- 你应该期望CPU使用率很高


如果其他应用程序响应缓慢,则在每个

块读/写之后放入DoEvents



<snip>

What actually gets slow ?

You are doing a heck of a lot of work
- you should expect the CPU usage to be high

If other Apps are responding sluggishly then put a DoEvents after each
block read/write


Bryan Rickard写道:
Bryan Rickard wrote:
我在VB6中编写了一个简单的程序,将所有文件从CD-ROM上的目录复制到我的硬盘上。大约有10个文件,每个大约有30MB。

程序使用Get和Put将CD中的数据放入缓冲区然后将其放入磁盘。见下面的代码。它有效,但在复制所有文件之前它会大幅减速。 Windows任务管理器
显示随着文件复制,CPU使用率逐渐增加,直到大约6个文件后达到100%。那就是它开始变慢的时候。

如何防止CPU使用量的增加?这是
代码的内容。这一切都在另一个循环中,遍历所有文件
在sCDPath中使用Dir
I wrote a simple program in VB6 to copy all the files from a directory
on a CD-ROM to my hard disk. There are about 10 files, each about
30MB.

The program uses Get and Put to get data from the CD into a buffer and
then put it into the disk. See code below. It works, but it slows
down drastically before it copies all the files. Windows Task Manager
shows the CPU usage gradually increasing as the files are copied,
until it reaches 100 percent after about 6 files. That''s when it
starts to get slow.

How can I prevent the CPU usage increasing? Here''s the guts of the
code. All this is within another loop that goes through all the files
in sCDPath with Dir


这篇关于从CD复制文件时,如何防止CPU使用率增加到100%?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆