I can write elements of the 8GB array all over the 8GB file using put #... but I can't put # the array itself... program just hangs.
All of my offsets and sizes look good to me. I can't figure out the issue.
The code comments have all of the details in this example... (compiles).
Code: Select all
' ================================================================
' TEST.bas
' Console program
' Running on Windows 10
' NOTE:
' - This requires FreeBASIC 64-BIT due to the 8GB array size.
' - !! == AND SOME RAM == !!
' - I have 32GB RAM - that's why I'm taking advantage of FB's
' large array capability.
' - I don't know how well it would run if it hit the Windows
' page file hard.
' ================================================================
'
' - Make a hits() 4G array of USHORT elements - (8GB array).
' - Update the hits() array and then put # the array to disk...
' - Program freezes.
' - I can put # individual elements all over the 8GB file space
' with no problem.
' - It's just when I try to put # the 8GB array that it freezes.
'
' 4294967295 ushort elements = 8GB array
redim shared hits( 0 to ((2^32)-1) ) as ushort
'
print
print "Bounds of hits() = "; lbound(hits); " to "; ubound(hits)
print "Size of hits() elements = "; sizeof(hits(1))
print
'
dim fbin as long
'
' Stick a few values throughout the hits() array...
hits(1) = 1
hits(7) = 2
hits(100) = 3
hits(1427429324) = 4
hits(3324216828) = 5
'
' Set initial length of file by writing to MAX ushort position.
' This works with no problem.
' Note:
' - Watch disk activity... I don't know if put # is initializing
' the 8GB file by writing all zeroes to it... or if Windows is
' doing it (???). But the disk is getting pounded as the file
' is being created.
fbin = freefile
open "C:\beh_TEMP\TEST-8GB-ARRAY.dat" for binary as #fbin
dim fbin_len as longint = ((2^32)*2) '8GB file.
dim fbin_value as ushort = &hffff
'
print date; "_"; time;" ... Setting max length of file - start ..."
put #fbin, fbin_len, fbin_value
print date; "_"; time;" ... Setting max length of file - done ..."
print
close #fbin
'
' Pause until the 8GB file is done being created (watch Task Manager).
dim gk as long
gk = getkey
'
' Write hits() array to file.
' Note:
' - There is no disk i/o when the put # statement is reached.
' - At the put #, the program just sits there. There is no more
' disk i/o... it doesn't get to the next print statement... it
' doesn't abend or blow up... ... it will just sit there forever.
' - After I break out of the program and hex view the file...
' that iniitial value I wrote at the end of the file is there,
' but none of the values in hits() are there - (as expected,
' since the program never did a close file).
fbin = freefile
open "C:\beh_TEMP\TEST-8GB-ARRAY.dat" for binary as #fbin
print date; "_"; time;" ... Writing hits() to file - start ..."
put #fbin, 1, hits()
print date; "_"; time;" ... Writing hits() to file - done ..."
print
close #fbin
'
END
Bruce