Hi Atul,
Yes, that’s wrong and you are right. I didn’t get reference counting quite right at first when I implemented the first Gnutella packets.
I guess you already know what the correct way to do that is, but for the sake of discussion, here is how I’ve done that now. Take a look at the new base class Protocols::Generics::Packet and e.g. the base class for BitTorrent packets Protocols::BitTorrent::Packets::Packet. In a nutshell the private data class of the derived class Packet class should derive from the private data class of the base class. The ctors of the derived class create a private object of the correct (derived) private data class and pass the pointer to the base ctor. The macros Q_DECLARE_SHARED_DATA and QS_D facilitate the use of the pointer to the private data from the base class by casting it to the private data of the derived class.
I just read what I wrote in the previous paragraph and it sound a bit weird but I think that reading the code will clear all question marks ;-)
Best regards,
Peter
atul wrote:reference counting Packet base class ( as there could be no object as it is not concrete )
and reference counting the concrete packets ( like pong ? )
I was wondering why to maintain Packet::Data::ref and Pong::Data::ref separately ( Packet::Data::ref could suffice maybe ? )
— cheerio atul
