[erlang-questions] append to a memory-mapped file
Morten Krogh
mk@REDACTED
Thu Dec 16 12:31:54 CET 2010
Hi
What about keeping variables with the file size, the size of your data,
and then when you want to append beyond the end of the file,
you ftruncate and mmap again. The ftruncate should be with much more
than 8 bytes of course. It is like mallocing much more than you need,
such that most
append operations are cheap. The file will then have the wrong size in
the file system. So when your process finishes, you should ftruncate
again to the final size.
If it crashes before that, then ??
You could use a marker in the file (zero byte?) to indicate the end and
use for crash recovery.
Morten.
On 12/16/10 11:43 AM, Joel Reymont wrote:
> Is there a way to append to a mmap-ed file such that appended data is available in the memory mapping?
>
> Yes, I plan to make the memory-mapped region available as a binary.
>
> I understand that I can just open and mmap the file again but that seems rather wasteful when appending 8 bytes at a time which is what I'll be doing.
>
> Thanks, Joel
>
> ---
> http://twitter.com/wagerlabs
>
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>
More information about the erlang-questions
mailing list