|
-
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]
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
|