[ENet-discuss] Announcing QENet - a Qt Wrapper for ENet

Thorbjørn Lindeijer bjorn at lindeijer.nl
Wed Oct 24 13:46:35 PDT 2012


On Wed, Oct 24, 2012 at 9:48 PM, Nathan Osman <nathan.osman at gmail.com> wrote:
> On Wed, Oct 24, 2012 at 3:21 AM, Thorbjørn Lindeijer <bjorn at lindeijer.nl>
>> Also, since the data is passed as a QByteArray signal parameter, this
>> necessitates creating a copy of the data. To avoid this
>> QByteArray::fromRawData could be used, but that's somewhat dangerous
>> for a library to do since this would make it illegal for the
>> QENetPacket (or its data) to be stored for later use unless an
>> explicit copy is made of its data while it is still allocated (since
>> it would be comparable to simply storing the char * and length
>> provided by enet).
>
>
> Right - I originally was just storing the ENetPacket * itself in QENetPacket
> and discovered (with the help of the debugger) that ENet automatically frees
> packets once they are sent. So instead I decided it would be easier to just
> copy the packet's contents immediately upon receipt and go from there. I'm
> pretty sure QByteArray uses copy-on-write and therefore passing a QByteArray
> around by value won't result in a bunch of data copying operations.

Yeah, since it does implicit sharing I was only talking about the
initial copy, but anyway that's not actually a performance issue given
the speed of networks compared to the speed of memory.

>> As for the automatic host service timer, maybe the library should just
>> expose a 'service' method (slot) so that the application using the
>> library can hook up a timer of its own at whatever desired frequency.
>
> I have no idea why I didn't think of this myself. Thank you! I have created
> a slot QENetHost::service() that can be called at any time to service the
> host or attached to another QTimer, etc. You can disable QENetHost's
> built-in timer by passing a value of 0 as the final parameter to create() -
> you will then need to make sure your code calls QENetHost::service() at
> regular intervals (such as in a game's main loop).

Nice. :-)

Best regards,
Bjørn


More information about the ENet-discuss mailing list