[erlang-questions] Error with Making a Big File

Magnus Klaar magnus.klaar@REDACTED
Thu Nov 24 18:06:55 CET 2011


Hi!

What you're attempting to do is to allocate a 1GB binary and write it in a
single system call, it _should_ work but it's not a reasonably small amount
of data to send around like that. Split it up into a sequence of smaller
writes of ... say 4KB at the time. It's also possible to allocate a sparse
file of a given size by seeking forward N bytes and writing a single byte.

For the first option something along these lines should work, i'd make sure
to verify that any edge cases aren't too broken.

 {ok, FD} = file:open(FName,[write,raw,binary]),

Bytes = 1000000000,

BSize = 4096,

BData = binary:copy(<<0>>, BSize),

[ok = file:write(FD, BData) || _ <- lists:seq(1, Bytes div BSize)],

BRemSize = Bytes rem BSize,

BRemData = binary:copy(<<0>>, BRemSize),

ok = file:write(FD, BRemData),

file:close(FD)

For the second options the operating system will lazily allocate blocks on
disk to back any data that you write to the file. This should work. Again
verify the edge conditions.

 {ok, FD} = file:open(FName,[write,raw,binary]),
{ok, _} = file:position(FD, {bof, Bytes}),
ok = file:write(FD, <<0>>).

MVH Magnus


On Thu, Nov 24, 2011 at 2:20 PM, Amir Almasi <amir.fireflame@REDACTED>wrote:

> Hi All,
>
> I am trying to make a file in Erlang with 1-GB size.
> This is a command:
>
> {ok,Io} = file:open(FName,[write,raw,binary]),
>              BitSize= 1000000000 * 8 ,
>              Reply = file:write (Io,<< 0 : BitSize >> ),
>              file:close(Io),
>
> And the problem would be:
> =ERROR REPORT==== 24-Nov-2011::13:53:24 ===
> Error in process <0.37.0> with exit value:
> {system_limit,[{erbitFile,loop,1},{erbitFile,init,0}]}
>
> I should mention that the operating system is windows!
>
> Please help me out with this matter,
>
> Regards,
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20111124/13179d8e/attachment.htm>


More information about the erlang-questions mailing list