How do I decide whether a method-function pointer belongs in the instance structure or class structure in GObject? but in gstreamer more function pointers put into instance structure,why?

Sebastian Dröge sebastian at centricular.com
Sun Dec 27 23:40:08 PST 2015


On So, 2015-12-27 at 18:43 -0800, zhang007z wrote:
> 
> I don't understand that the method function pointer puts in class or
> instance structure that it seen to same . what difference are they? I
> think that class function method pointers each of instance object is
> used to call same, so puting this functions to class structure.
> However, How to use instance object's function method pointers about
> method pointers of its own?
> because I think the function method pointers of instance object for
> itself is same, How to understand instance object function method?
> below I give that gstreamer Gstpad.h code snippet as example :
> [...]
> so I confuse this issue,why there are function method pointers in
> intance structure rather than puting into class class structure?
> 

You put the function pointers into the class struct if you want them to
behave like virtual methods in other languages. That is, each object
instance of a specific class is going to have exactly the same
implementation of that method, but different subclasses of the defining
class can have different implementations (e.g. GstPad has a different
GObject::finalize() implementation than GstElement).

You put them into the instance struct if they're more to behave like
callbacks and different instances of the same class should be able to
have different implementations of them.

-- 
Sebastian Dröge, Centricular Ltd · http://www.centricular.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 949 bytes
Desc: This is a digitally signed message part
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20151228/eee0eb23/attachment.sig>


More information about the gstreamer-devel mailing list