[ENet-discuss] Can modifying packet->dataLength cause leaks?
Kazin Lujan
xkazinx at gmail.com
Sun Apr 9 21:49:29 PDT 2017
Say you have to write 100 strings:
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?
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.
2017-04-10 0:25 GMT-03:00 Lee Salzman <lsalzman at gmail.com>:
> Use enet_packet_resize to grow the packet. That's what it exists for.
>
> On Sun, Apr 9, 2017 at 11:00 PM, Kazin Lujan <xkazinx at gmail.com> wrote:
> > Could modifying packet->dataLength before being sent cause a leak?
> >
> > I'm setting it to 0 after I create it and increasing the value based on
> the
> > data I'm writing into packet->data.
> >
> > I'm doing this when I don't know what will be the exact size of the data
> to
> > be sent.
> >
> > I assume enet will destroy all the data regardless of the dataLength
> value
> > since it uses packet->data = enet_malloc(...) to allocate in
> > enet_packet_create and enet_free(packet->data) to deallocate in
> > enet_packet_destroy(...), but I don't know about enet's internal
> processes.
> >
> > Example code: https://pastebin.com/QdaHjqft
> >
> > _______________________________________________
> > ENet-discuss mailing list
> > ENet-discuss at cubik.org
> > http://lists.cubik.org/mailman/listinfo/enet-discuss
> >
> _______________________________________________
> ENet-discuss mailing list
> ENet-discuss at cubik.org
> http://lists.cubik.org/mailman/listinfo/enet-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubik.org/pipermail/enet-discuss/attachments/20170410/a55b8ca0/attachment.html>
More information about the ENet-discuss
mailing list