[erlang-questions] Preallocated binary — save memory

Anthony Ramine n.oxyde@REDACTED
Wed Apr 10 10:13:34 CEST 2013

Hello Max,

There already exists a BEAM instruction that preallocates a binary: bs_init_writable. From what I understand it is only used when compiling bit string comprehensions when their body expression and binary generators' patterns only have sized fields and they have no list generators or filters.

Could you rewrite your decoder in such a bit string comprehension?


Anthony Ramine

Le 10 avr. 2013 à 08:58, Max Lapshin a écrit :

> There is a problem in erlyvideo with generating mpeg-ts.
> I have list of video frames, they are binaries of 4K - 100K bytes size with some additional metadata. I need to split all these binaries in chunks of about 184 bytes and create lots of such chunks.
> When mpeg-ts transformation is written in C, large binary is allocated (size = sum(frame_size)*C) and all frames with additional data are written to this block chunk by chunk.
> Only one memory allocation is done and only one copy is done.
> When I write it in erlang, lots (thousands) of small binaries are allocated and iolist_to_binary makes another copy with another allocation.
> May it be a good idea to add nif function that returns large preallocated binary and then generate such data with <<Data/binary, Chunk/binary>> so that no reallocation is done?
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

More information about the erlang-questions mailing list