CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2004
    Location
    Wuhan, China
    Posts
    32

    Question help: howto prealloc a large file in disk?

    Hi, everyone
    I want to process a large image(maybe 1G), and write the processed result into an output file, but the procession is not a sequential one, so i maybe start to write from the EOF. My question is how to pre-allocate the required space in disk so i can write anywhere in the file when needed. I have tried using WriteFile API but it is too slow, it cost 55 milliseconds to wirte a 1G file , does anyone has better solutions?
    When i use bittorrent, I notice that its pre-allocation is very fast, perhaps less than 1s.
    Any comments will be appreciated
    Thanks for helping!
    Last edited by reviver; September 13th, 2004 at 11:07 PM.

  2. #2
    Join Date
    Apr 2002
    Location
    St.Petersburg, Russia
    Posts
    714

    Re: help: howto prealloc a large file in disk?

    Try following sequence:
    Code:
    SetFilePointer(hFile, 1024*1024*1024, NULL, FILE_BEGIN);
    SetEndOfFile(hFile);
    SetFilePointer(hFile, 0, NULL, FILE_BEGIN);
    I don't checked this, but I think that it should work.
    With best wishes, Alexander Hritonenkov

  3. #3
    Join Date
    May 2004
    Location
    Wuhan, China
    Posts
    32

    Smile Re: help: howto prealloc a large file in disk?

    Thanks! it works.
    I thought SetFilePointer can only move pointer in the actual range before.
    Thanks again!
    Time is a great teacher, but unfortunately it kills all its pupils.

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