Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Buffer.add error
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-01-08 (10:08)
From: Basile STARYNKEVITCH <basile@s...>
Subject: [Caml-list] Buffer.add error
>>>>> "Mikkel" == Mikkel Christiansen <> writes:

    Mikkel> Hi I'm having trouble with the buffer library in ocaml
    Mikkel> (version 3.06 - debian). Program was compiled to native
    Mikkel> using ocamlopt.

    Mikkel> When generating a rather large string I get the following
    Mikkel> error:

    Mikkel>     Fatal error: exception Failure("Buffer.add: cannot
    Mikkel> grow buffer")

    Mikkel> Is there any way to avoid this (except writing directly to
    Mikkel> a file)?

I suggest looking into the sources. In ocaml/stdlib/ you can
read (near line 43)

    if b.position + more <= Sys.max_string_length
    then new_len := Sys.max_string_length
    else failwith "Buffer.add: cannot grow buffer"

So basically, you are hitting the limits of maximal string size (which
is 2^24 = 16777216 on 32 bits plateform).

Hence you cannot avoid it, except by switching to a 64 bits plateform.

You might change your algorithms - perhaps by keeping in memory a
vector of buffers or lines or paragraphs (whatever these are in your


email: basile<at>starynkevitch<dot>net 
alias: basile<at>tunes<dot>org 
8, rue de la Faïencerie, 92340 Bourg La Reine, France
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: