<div dir="ltr"><div><div><div>> 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?<br></div>How about if you do that, without preallocating, just starting with <<>>?<br></div>That would at least lower the number of allocations to O(log(number_of_chunks)).<br></div>And if that doesn't cut it, sure - do the same except hand-craft a BEAM function which does the preallocation... it sounds like that is possible without resorting to NIFs :-)<br>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/4/10 Max Lapshin <span dir="ltr"><<a href="mailto:max.lapshin@gmail.com" target="_blank">max.lapshin@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">There is a problem in erlyvideo with generating mpeg-ts.<div><br></div><div>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.</div>
<div><br></div><div>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.</div><div>
<br></div><div>Only one memory allocation is done and only one copy is done.</div><div><br></div><div><br></div><div>When I write it in erlang, lots (thousands) of small binaries are allocated and iolist_to_binary makes another copy with another allocation.</div>
<div><br></div><div>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?</div>
<div><br></div></div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>