<div dir="ltr">Say you have to write 100 strings: <div><br></div><div>Would you consider it better (in benchmark terms) to write their content into a big buffer and then memcpy(ing) it into a packet being created with the written size, or writing directly into packet->data and resizing it each time a string is being written when the written size exceeds the packet's size?</div><div><br></div><div>I wanted to alter packet->dataLength to manipulate the amount of data being sent so that a single allocation is needed in case the exact size is a bit messy to calculate (I used strings as an example). If it's not viable, sounds like the first option could work.</div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-04-10 0:25 GMT-03:00 Lee Salzman <span dir="ltr"><<a href="mailto:lsalzman@gmail.com" target="_blank">lsalzman@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Use enet_packet_resize to grow the packet. That's what it exists for.<br>
<div><div class="h5"><br>
On Sun, Apr 9, 2017 at 11:00 PM, Kazin Lujan <<a href="mailto:xkazinx@gmail.com">xkazinx@gmail.com</a>> wrote:<br>
> Could modifying packet->dataLength before being sent cause a leak?<br>
><br>
> I'm setting it to 0 after I create it and increasing the value based on the<br>
> data I'm writing into packet->data.<br>
><br>
> I'm doing this when I don't know what will be the exact size of the data to<br>
> be sent.<br>
><br>
> I assume enet will destroy all the data regardless of the dataLength value<br>
> since it uses packet->data = enet_malloc(...) to allocate in<br>
> enet_packet_create and enet_free(packet->data) to deallocate in<br>
> enet_packet_destroy(...), but I don't know about enet's internal processes.<br>
><br>
> Example code: <a href="https://pastebin.com/QdaHjqft" rel="noreferrer" target="_blank">https://pastebin.com/QdaHjqft</a><br>
><br>
</div></div>> ______________________________<wbr>_________________<br>
> ENet-discuss mailing list<br>
> <a href="mailto:ENet-discuss@cubik.org">ENet-discuss@cubik.org</a><br>
> <a href="http://lists.cubik.org/mailman/listinfo/enet-discuss" rel="noreferrer" target="_blank">http://lists.cubik.org/<wbr>mailman/listinfo/enet-discuss</a><br>
><br>
______________________________<wbr>_________________<br>
ENet-discuss mailing list<br>
<a href="mailto:ENet-discuss@cubik.org">ENet-discuss@cubik.org</a><br>
<a href="http://lists.cubik.org/mailman/listinfo/enet-discuss" rel="noreferrer" target="_blank">http://lists.cubik.org/<wbr>mailman/listinfo/enet-discuss</a><br>
</blockquote></div><br></div>