[ENet-discuss] ENet performance (packet reuse/allocation, channel count...)
Kevin Gadd
kevin.gadd at gmail.com
Mon May 1 21:27:04 PDT 2006
This looks great - one question, though. Is there any straightforward way of
detecting when a block of memory is no longer being used by a packet so that
I can free up that memory? Getting a 'type' argument to the free() callback
would be sufficient, but it might also be nice to just have a specialized
'packetDestroyed' callback that lets the user know that a packet's data is
no longer in use.
In my specific case, to be able to pass a data pointer to enet, I have to
pin the data in memory first because I'm using a garbage-collected VM, so I
need to know when the data is no longer in use so that it can be unpinned
and GCed.
Thanks
-k
On 5/1/06, Lee Salzman <lsalzman1 at cox.net> wrote:
>
> Just because I felt inspired I will eventually add something similar to
> the following code to the main ENet branch. If you really want, just
> manually apply these diffs for now, and when I get around to the next
> release it will be in there. You can consider the interface to it
> (ENET_PACKET_FLAG_NO_ALLOCATE) final, so don't worry about using it. It
> will just use the pointer passed to enet_packet_create() verbatim rather
> than copying from it.
>
> Index: packet.c
> =================================> RCS file: /cvsroot/sauerbraten/sauerbraten/src/enet/packet.c,v
> retrieving revision 1.2
> diff -u -r1.2 packet.c
> --- packet.c 24 Mar 2006 21:14:07 -0000 1.2
> +++ packet.c 2 May 2006 04:13:31 -0000
> @@ -21,10 +21,15 @@
> {
> ENetPacket * packet > (ENetPacket));
>
> - packet -> data > + if(flags & ENET_PACKET_FLAG_NO_ALLOCATE)
> + packet -> data > + else
> + {
> + packet -> data >
> - if (data !> - memcpy (packet -> data, data, dataLength);
> + if (data !> + memcpy (packet -> data, data, dataLength);
> + };
>
> packet -> referenceCount > packet -> flags > @@ -39,7 +44,8 @@
> void
> enet_packet_destroy (ENetPacket * packet)
> {
> - enet_free (packet -> data);
> + if((packet -> flags & ENET_PACKET_FLAG_NO_ALLOCATE) = 0)
> + enet_free (packet -> data);
> enet_free (packet);
> }
>
> @@ -54,7 +60,7 @@
> {
> enet_uint8 * newData;
>
> - if (dataLength <> + if (dataLength <> ENET_PACKET_FLAG_NO_ALLOCATE))
> {
> packet -> dataLength >
> Index: include/enet/enet.h
> =================================> RCS file: /cvsroot/sauerbraten/sauerbraten/src/enet/include/enet/enet.h,v
> retrieving revision 1.8
> diff -u -r1.8 enet.h
> --- include/enet/enet.h 1 May 2006 19:24:17 -0000 1.8
> +++ include/enet/enet.h 2 May 2006 04:13:31 -0000
> @@ -80,7 +80,9 @@
> /** packet will not be sequenced with other packets
> * not supported for reliable packets
> */
> - ENET_PACKET_FLAG_UNSEQUENCED > + ENET_PACKET_FLAG_UNSEQUENCED > + /** packet will not allocate data, and user must supply it instead */
> + ENET_PACKET_FLAG_NO_ALLOCATE > } ENetPacketFlag;
>
> /**
>
> Kevin Gadd wrote:
> > Perfect. Being able to send the same packets multiple times will be a
> > godsend - glad that's possible. Probably wouldn't hurt to document that
> > somewhere. :)
> >
> > I noticed the callbacks stuff in the new version of the library but
> > didn't notice that it was for allocation. Makes sense. Is there any way
> > to turn the callbacks on and off dynamically so that I can only use them
> > when I'm creating a packet from an existing memory buffer?
> >
> > Thanks!
> > -kg
> >
> _______________________________________________
> 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/20060501/620cc2d9/attachment-0001.htm
More information about the ENet-discuss
mailing list