标签:read 原理 ext hand use i know nal HERE class
13∶13
wsgalaxy hi,I am learning gtk, and I am confused about the private data of gobject
If class C extends B, and B extends A, could b have the private data struct defined by G_ADD_PRIVATE ?
It seems that the private data struct is append after the instance struct, and if the instance is extended by other class, the private data struct is overwrited
13∶29
exalm[m] wsgalaxy: class C struct will have class B struct embedded (which will have class A struct in it, etc), including a pointer to its private data struct somewhere inside (useless, since you cannot do anything with it)
tristan joined
SilverRainZ has disconnected (Read error)
hmmmm has disconnected (Read error)
SilverRainZ joined
15∶00
wsgalaxy exalm[m]: Do you mean that the private data pointer is stored outside the inheritance tree of instance struct?
exalm[m] wsgalaxy: inheritance tree? It‘s just a field in a struct, the inheritance here is including parent struct as is (since it‘s not pointer). And only a pointer to private struct is stored, so that one isn‘t directly included
4 users joined, 1 user left?15∶26
wsgalaxy https://paste.gnome.org/puhzhhytx
As describe below, where would the private data pointer be stored?
I mean ‘above‘... my poor english..
Company wsgalaxy: there‘s the get_instance_private() function
baedert[w] wsgalaxy: You can always read the code if the documentation doesn‘t explain something and you want to know internals: https://gitlab.gnome.org/GNOME/glib/blob/master/gobject/gtype.c#L1846
Company it‘s a neat magic trick that glib pulls about hiding the private data
wsgalaxy: usually an object would be in memory like this (without private data):
[ Object | Widget | Button ]
↖ pointer used
with private data, glib handles objects like this:
[ ButtonPrivate | WidgetPrivate | ObjectPrivate | Object | Widget | Button ]
↖ pointer used
(yay, hexchat screws that up completely)
all of these structs have a known size, so going from the actual used pointer to the relevant priv pointer is just a subtraction
which is what get_instance_private() does
wsgalaxy oh, I know , so the private data is store before the object struct but not after......this make me clear, thanks for your wonderful explanation!!!??
Company ??
关于gobject中使用private data的原理的讨论
标签:read 原理 ext hand use i know nal HERE class
原文地址:https://www.cnblogs.com/wsgalaxy/p/10059005.html