[ENet-discuss] Using packet-data w/o a memcpy()?

Mike Diehl mdiehl at diehlnet.com
Wed May 12 00:54:08 PDT 2010


On Wednesday 12 May 2010 1:27:56 am RAULO Emmanuel IT&L at bs wrote:
> Hello Mike,
>
> Mike Diehl a écrit :
> > switch (event.type) {
> > 	case ENET_EVENT_TYPE_RECEIVE:
> >
> > 		// XXX Are we really going to do a memcpy here?
> > 		memcpy(P, event.packet->data, event.packet->dataLength);
> > 		break;
> > }
> >
> > How do I convert the
> > EnetPacket* to a void* without simply copying it to a char[]?
>
> Well, event.packet->data *IS* a void*, you don't have to copy it if
> you're that concerned about performance and can just process the data in
> place.
> By the way, you will have to call enet_packet_destroy(packet) once
> you're done processing packet data.
>
> Cheers,
>
> --
> Emmanuel

My reading of the docs indicate that event.packet-data is a enet_uint8 *, 
which is typecast from a pointer to char.  This implies that I should be able 
to cast it to void*

void	*buffer;

buffer = (void) event.packet->data;

But this didn't seem to work.  Like I said, I'm a bit rusty...  So I was on 
the right track?  I just have to fiddle with syntax, then.

As to the call to enet_packet_destroy(), yes, I was going to process the 
packet and make that call immediately afterward.


-- 

Take care and have fun,
Mike Diehl.


More information about the ENet-discuss mailing list