-
May 31st, 2000, 09:04 AM
#1
Writing to disk without caching
I am attempting to copy file to disk without caching.The code belows details have I am attempting to implement this feature. I am having problems copying files that are much larger than my (typically 256K) buffer. For example if my file size is 1096K. I successfully copy the first 1024K, but the WriteFile operation fails on the last 72K. If my file is 300K the write is successfull. If my file is less that 256K the write is successfull.
[ccode]GetDiskFreeSpace(RootPathName,&dwSectorsPerCluster,&dwBytesPerSector,
&dwNumberOfFreeClusters, &dwTotalNumberOfClusters);
dwBytesToRead = dwBytesPerSector * 200;
pBuffer = VirtualAlloc(NULL,dwBytesToRead , MEM_COMMIT,PAGE_READWRITE | PAGE_NOCACHE);
if(!pBuffer || !CheckFileErrors() )
break;
do
{
bResult = ReadFile(hFromTemp,pBuffer,dwBytesToRead,&dwNumberOfBytesRead,NULL);
if(!bResult || !CheckFileErrors() )
break;
if(!WriteFile(hToTemp,pBuffer,dwNumberOfBytesRead,&dwNumberofBytesWritten,NULL))
{
bResult = FALSE;
CheckFileErrors();
break;
}
m_i64TotalSizeCopied += dwNumberofBytesWritten;
m_lSizeCopied = static_cast<long>(m_i64TotalSizeCopied);
}
while((!bResult && dwNumberOfBytesRead != 0) || (dwBytesToRead = dwNumberofBytesWritten));
[\ccode]
-
June 4th, 2000, 05:30 PM
#2
Re: Writing to disk without caching
Can I ask why you want to write a file that is not cached?
There is a CopyFile function which will copy a file for you.
Dave McLelland
D. McLelland (Software) Limited
Dave Mclelland.
-
November 20th, 2003, 08:18 PM
#3
I'd like to write to a file without caching as well.
It's useful in some circumstances including things like event logging.
So how is it done ?
Thanks,
Rob
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|