-
July 5th, 2007, 03:35 PM
#1
[RESOLVED] fstream::seekg 64 bit?
Hello fellow gurus,
I am trying to read/write files that can possibly get extremely large.
However, fstream::seekg/seekp cannot handle 64bit positions.
How would I go about reading/writing to positions that exceed 4GB?
The file format itself provides offset information in QWORDS.
I have thought about jumping from one offset to another until I get where I want to go, but that seems like a hack.
My idea was as follows:
Code:
void SeekFStream(fstream& s, __int64 pos)
{
s.seekg(0, ios::beg);
UINT n4GBSeeks = pos / 0xFFFFFFFF;
for(UINT i = 0; i < n4GBSeeks; i++)
{
s.seekg(0xFFFFFFFF, ios::cur);
}
// Rest
s.seekg(pos % 0xFFFFFFFF, ios::cur);
}
Could that work? Also, can fstream handle >4GB internally?
Any help would be appreciated.
Last edited by namezero111111; July 5th, 2007 at 03:45 PM.
-
July 5th, 2007, 04:57 PM
#2
Re: fstream::seekg 64 bit?
Originally Posted by namezero111111
Hello fellow gurus,
I am trying to read/write files that can possibly get extremely large.
However, fstream::seekg/seekp cannot handle 64bit positions.
Just one thing -- whether you can use 64-bit offsets using fstream is implementation defined by your STL vendor and what they have defined as std::ios::pos_type.
Since your file system allows files > 4GB, does your OS have dedicated API functions to handle files? If so, then use those functions instead of fstream.
Regards,
Paul McKenzie
-
July 5th, 2007, 06:40 PM
#3
Re: fstream::seekg 64 bit?
Thank you for your reply.
It is my understanding that the Windwos NT/2000/XP series _can_ handle files exceeding 4GB.
Any suggestions of which functions handle such files?
I'm sure it's something in the Windows API; any ideas?
-
July 5th, 2007, 06:46 PM
#4
Re: fstream::seekg 64 bit?
Originally Posted by namezero111111
It is my understanding that the Windwos NT/2000/XP series _can_ handle files exceeding 4GB.
Any suggestions of which functions handle such files?
I'm sure it's something in the Windows API; any ideas?
SetFilePointer() / ReadFile()
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
July 5th, 2007, 06:58 PM
#5
Re: fstream::seekg 64 bit?
Thank you!
I have found that there are also CreateFile() and CloseHandle(), which are the equivalent to fstream:pen() & fstream::close().
-
July 5th, 2007, 07:01 PM
#6
Re: fstream::seekg 64 bit?
Originally Posted by namezero111111
Thank you!
You are welcome.
Originally Posted by namezero111111
I have found that there are also CreateFile() and CloseHandle()...
You got it!
Originally Posted by namezero111111
...which are the equivalent to fstream: pen() & fstream::close().
Hmmm... Apparently, not very "equivalent"...
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
July 5th, 2007, 10:25 PM
#7
Re: fstream::seekg 64 bit?
Hehe...
almost equivalent...
What I meant was that they perform the equivalent tasks on a file handle as the fstream functions on the object : )
Thanks again!
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
|