In my tests on WinXP, it looks like
the sensible limit is 2147483647 == to-integer #{7FFFFFFF}
However, in my tests (see code below),
the size integer returned by INFO? wraps
around to -2147483648 and continues up from
there as you increase the file size, so at least
on WinXP you can get up to 4 Gigabytes (minus 1) and still accurately
test for size (albeit with a bit of careful integer hackery).
When 4Gig is reached, the size returned is zero.
If you further increase the file size from here,
then INFO? just gives a zero size result.

Anton.

> If the size of a file is larger than the max
> value of an integer, how can I then retrieve
> the size?
>
> Thank you
>
> Steffen

(watch out for unintended line wrapping...)

rebol [
        Title: ""
        File: %test-max-file.r
        Date: 12-Dec-2004
        Version: 1.0.0
        Needs: []
        Author: "Anton Rolls"
        Language: 'English
        Purpose: {Determine maximum file size which can be tested accurately}
        Usage: {}
        ToDo: {
        -
        }
        History: [
                1.0.0 [12-Dec-2004 {First version} "Anton"]
        ]
        Notes: {
                In rebol, file sizes are typically stored in signed integers.
                Therefore the theoretical limit is:
                2147483647 == to-integer #{7FFFFFFF}
        }
]

file: %/L/big-rebol-file ; <- on a volume with enough space !!

; create a large string, but not so large it exhausts our memory

block-size: 1024 * 1024 * 16 ; 16 Megabytes

str: make string! block-size  ; pre-allocate the string
insert/dup str "1" block-size ; <- fill the string
str-1: copy/part str back tail str ; <- one character less

if exists? file [delete file]

expected-size: 0

repeat n 255 [ ; (also try to 127)
        print [n "^-Expected size:" expected-size "^-SIZE? size:" size? file]
        write/append file str
        expected-size: attempt [expected-size + block-size] ; catch integer
overflow errors
]

print ["SIZE? size:" size? file]

write/append file str-1 ; just below overflow limit
print ["SIZE? size:" size? file] ; <- size comes back as a negative number

write/append file "F" ; <- this causes the size integer overflow (number
becomes negative)
print ["SIZE? size:" size? file]

write/append file "1"
print ["SIZE? size:" size? file]

;halt

-- 
To unsubscribe from the list, just send an email to rebol-request
at rebol.com with unsubscribe as the subject.

Reply via email to