CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2000
    Posts
    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]


  2. #2
    Join Date
    May 2000
    Location
    Scotland, Livingston.
    Posts
    728

    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.

  3. #3
    Join Date
    Nov 2003
    Location
    Ontario Canada
    Posts
    5
    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
  •  





Click Here to Expand Forum to Full Width

Featured