dos/windows 2 gig file limit

General FreeBASIC programming questions.
Post Reply
MystikShadows
Posts: 612
Joined: Jun 15, 2005 13:22
Location: Upstate NY
Contact:

dos/windows 2 gig file limit

Post by MystikShadows »

Hi all,

Maybe victor can answer this if he remembers, but at one point, he posted code, here or on the qbasicnews forum.

I think (not sure) the code used the windows API to open files in 64bit mode so to speak so that the classic 2 gig file sile limite could be overcome with that code.

Anyone know what I'm talking about? :)

I've searched here and on the qbasicnews forum before posting this. to no avail.
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Post by MichaelW »

Running under Windows 2000 and using Version 0.21.0 (03-09-2009) I can exceed that limit with this code:

Code: Select all

dim as string filler
filler = string(1000000,"X")
open "d:\bigfile.bas" for output as 1
for i as integer = 1 to 3000
    locate 1,1,0
    print i;
    print #1, filler;
next
print
print lof(1)
close
sleep
kill "d:\bigfile.bas"
print "OK"
sleep
cls
open "d:\bigfile.bas" for binary as 1
for i as integer = 1 to 3000
    locate 1,1,0
    print i;
    put #1,, filler
next
print
print lof(1)
close
sleep
kill "d:\bigfile.bas"
print "OK"
sleep
It takes several minutes to create the file, and on a system with only 512MB of memory it’s hard to do much with the file, but the created file appears to be OK and the reported size is correct.

I did find a Microsoft KB article that shows how to overcome VBA’s 2GB limit by using the API directly:

http://support.microsoft.com/kb/189981
MystikShadows
Posts: 612
Joined: Jun 15, 2005 13:22
Location: Upstate NY
Contact:

Post by MystikShadows »

Thank you MichaelW,

Hmmm, i'm running XP Pro on one laptop and Vista Home Basic and both seem to work good with your code. awesome. As you say, files seem intact and written as expected. I'll do further testing to make sure they are indeed 100% safe :)

If Victor reads this and remembers the code he posted, if you can post it again just for references :)
v1ctor
Site Admin
Posts: 3804
Joined: May 27, 2005 8:08
Location: SP / Bra[s]il
Contact:

Post by v1ctor »

Michael and Zippy are the Win API masters here, i can't remember ever using it to do file manipulation, sorry (my memory is quite bad though, i'm getting too old, some will say, heh).

But, if i remember (hmm, hmm), DrV added support for huge-files >2GB to the runtime library releases ago, so any file function/statement should work.
Hard
Posts: 135
Joined: Aug 29, 2008 21:13

Post by Hard »

api commands:

CREATEFILE
GETFILESIZEEX
SETFILEPOINTER
READFILE
WRITEFILE
CLOSEHANDLE

my ftp server is based on it and works fine with files bigger than 50gb
Post Reply