Problem with PUT

General FreeBASIC programming questions.
Post Reply
Provoni
Posts: 514
Joined: Jan 05, 2014 12:33
Location: Belgium

Problem with PUT

Post by Provoni »

Hey all,

Following program freezes when the output file is around 3.5GB. Does PUT not work with big files? FBC 1.07.1, Win10, 64GB RAM.

Thanks

Code: Select all

screenres 512,384,32

static shared as ubyte array() '8GB
redim array(8000000000)

open "test8gb.txt" for binary access write as #1
put #1,,array()
close #1

beep
sleep
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Problem with PUT

Post by jj2007 »

On my Win7-64 machine it doesn't freeze, but it doesn't write anything either. Some error checking might help.

Code: Select all

#include "Windows.bi"
static shared as ubyte array() '8GB
redim array(8000000000)
print "GetLastError=";GetLastError(), " (8=not enough memory)"
open "test8gb.txt" for binary access write as #1
print "putting"
put #1,,array()
print "closing"
close #1

sleep
With 8GB, I get "not enough memory" (my system has 6GB). This is the error returned by RtlAllocateHeap.
dodicat
Posts: 7987
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Problem with PUT

Post by dodicat »

I don't have enough ram here, but does the crt file handling work better?

Code: Select all



#include "crt.bi"

#include "file.bi"

#macro Csave(filename,arr)
Scope
    Dim As file Ptr f = fopen((filename), "wb")
    fwrite(Cptr(Typeof(arr) Ptr,@arr(lbound(arr))),sizeof(arr),ubound(arr)-lbound(arr)+1,f)
    fclose(f)
End Scope
#endmacro

#macro Cload(filename,arr)
Scope
    Dim As file Ptr f = fopen((filename), "rb")
    fread(Cptr(Typeof(arr) Ptr,@arr(lbound(arr))),sizeof(arr),ubound(arr)-lbound(arr)+1,f)
    fclose(f)
End Scope
#endmacro

dim as long size=500000000
print "size ";size/1000000000;"  gb"

redim  as ubyte u(size)
clear u(0),4,size
for n as long=1000000 to 1000050
print u(n);" ";
next
print
print "saving"
csave("ctest.txt",u)
print "saved"
print "file length ";filelen("ctest.txt")
redim  as ubyte v(size)
print "re-loading"
cload("ctest.txt",v)
print "Loaded"
print
for n as long=1000000 to 1000050
print v(n);" ";
next
print

kill "ctest.txt"
print iif(filelen("ctest.txt")=0,"OK","Delete file manually")
sleep

 
fxm
Moderator
Posts: 12158
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Problem with PUT

Post by fxm »

For 32-bit fbc, maximum dynamic data <2 GB.

For 64-bit fbc, maximum dynamic data <virtual memory,
with virtual memory = physical RAM + SWAP files (roughly)
Provoni
Posts: 514
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Problem with PUT

Post by Provoni »

jj2007 wrote:On my Win7-64 machine it doesn't freeze, but it doesn't write anything either. Some error checking might help.

Code: Select all

#include "Windows.bi"
static shared as ubyte array() '8GB
redim array(8000000000)
print "GetLastError=";GetLastError(), " (8=not enough memory)"
open "test8gb.txt" for binary access write as #1
print "putting"
put #1,,array()
print "closing"
close #1

sleep
With 8GB, I get "not enough memory" (my system has 6GB). This is the error returned by RtlAllocateHeap.
GetLastError=0
putting (forever... stuck at about 3.5GB)

Win10 64-bit, 64GB RAM system.
Provoni
Posts: 514
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Problem with PUT

Post by Provoni »

dodicat wrote:I don't have enough ram here, but does the crt file handling work better?
When I try 8GB with your example it says: warning 25(0): Overflow in constant conversion, and no file is made.

I've worked arount the PUT issue by buffering it.
Post Reply