🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: File Copy Operation

#16335
From: Vladimir Afanasyev
Date: Fri, 16 May 2003 14:13
52 lines
3010 bytes
"Remy Lebeau \(TeamB\)" <gambit47@yahoo.com> wrote:
>If you're conserned about speed, then memory mapping the soource file will
>be much faster then using ReadFile() for it.  By mapping the file into
>memory (CreateFileMapping() and MapViewOfFile()), you can access the file
>data directly as a simple BYTE* array, hardly any disk I/O is used at all
>(except for maybe occasional page swapping if the file is very large).  Disk
>I/O is always a bottleneck when performing data processing, so the more
>processing you can do in memory directly, the better the performance will
>be.
>

I think that file mapping is not much faster then Win32 API 
in this case. Most data on CDROM and even those that is 
located on HDD CDROM could be changes - it is source file.
So PAGE_WRITECOPY should be used like follow:

hFile = CreateFile("D:\\Software\\Drivers\\TWSWTCP\\TWSWTCP.exe", GENERIC_READ , FILE_SHARE_READ, NULL, OPEN_EXISTING,
        FILE_ATTRIBUTE_NORMAL, 0);

if(hFile == INVALID_HANDLE_VALUE)
        {
         DWORD ddd=GetLastError();
         return;
        }

hFileMapping = CreateFileMapping(hFile, NULL, PAGE_WRITECOPY, 0, 0, NULL);
if(hFileMapping == 0)
        {
         CloseHandle(hFile);

         return;
        }

lpFileBase = MapViewOfFile(hFileMapping, FILE_MAP_COPY, 0, 0, 0);
if(lpFileBase == 0)
        {
         CloseHandle(hFileMapping);
         CloseHandle(hFile);

         return;
        }

Microsoft said that for PAGE_WRITECOPY are both GENERIC_READ 
and GENERIC_WRITE are needed but it is incorrect for CDROM 
(only GENERIC_READ). When PAGE_WRITECOPY will be used 
then the pages will automatically swappable after changes for 
big files (files that can't be loading as a whole). 
If file can be loadind entirely it means that it can be 
loading entirely via ReadFile API.

Vladimir.
Technical Details
Message-ID: <3ec4f227$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-08!supernews.com!newsswitch.lcs.mit.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail
References: <3ec35dd4@newsgroups.borland.com> <3ec3944e$1@newsgroups.borland.com> <3ec3be2e@newsgroups.borland.com> <3ec3c37a@newsgroups.borland.com> <3ec41b29$1@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-16 07:17:13 PST
From: "Vladimir Afanasyev" <avv@systema.kiev.ua>
Sender: "Vladimir Afanasyev" <avv@systema.kiev.ua>
Reply-To: "Vladimir Afanasyev" <avv@systema.kiev.ua>
Subject: Re: File Copy Operation
Newsgroups: borland.public.cppbuilder.nativeapi
X-User-Info: 62.244.14.114 62.244.14.114    
X-Forwarded-For: 192.168.0.147
References: <3ec35dd4@newsgroups.borland.com> <3ec3944e$1@newsgroups.borland.com> <3ec3be2e@newsgroups.borland.com> <3ec3c37a@newsgroups.borland.com> <3ec41b29$1@newsgroups.borland.com>
NNTP-Posting-Host: 207.105.83.65
Message-ID: <3ec4f227$1@newsgroups.borland.com>
Date: 16 May 2003 07:13:59 -0700
X-Trace: newsgroups.borland.com 1053094439 207.105.83.65 (16 May 2003 07:13:59 -0700)
Lines: 52
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-08!supernews.com!newsswitch.lcs.mit.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail