/srv/irclogs.ubuntu.com/2009/08/28/#upstart.txt

=== robbiew is now known as robbiew-afk
sadmacKeybuk: thought: nih_discard should run the destructor always.05:07
Keybuksadmac: why?09:39
sadmac2Keybuk: Think of it in the case of our most common destructor: removing the node from a list. Discard should only leave the item around for people still referencing it, which means external references like that should go away.14:17
=== robbiew-afk is now known as robbiew
Keybukright, but that's not how it's supposed to work ;-)14:37
Keybukdiscard is "drop the NULL reference"14:37
Keybukthe assumption is that you allocate an object with a NULL reference, pass it to something that actually references it14:38
Keybukand then drop the NULL ref14:38
Keybukif it didn't get referenced, dropping the NULL ref does free it14:38
Keybuke.g.14:38
Keybukvoid *foo;14:38
Keybukfoo = nih_new (NULL, SomeObject);14:38
Keybuknih_list_init (&foo->entry);14:39
Keybukpass_to_some_func (foo);14:39
Keybuknih_discard (foo);14:39
Keybuk...14:39
Keybukwhere14:39
Keybukpass_to_some_func (void *foo)14:39
Keybuk{14:39
Keybuk    nih_list_add (&foos, &foo->entry);14:39
Keybuk    nih_ref (foo, &foos);14:39
Keybuk}14:39
sadmac2well that's what it /does/ sure :) The name to me implies "normal operation of the program is done with this object. Only keep it around if something hasn't remembered to dereference it yet."14:41
sadmac2In a more literal sense, "discarding" the object should take it out of a list.14:42
Keybukit's more equivalent to g_ref_sink in the old libgtk style referencing14:42
sadmac2Keybuk: also I've occasionally found a list that I'd prefer used internal referencing (i.e. actually do nih_ref (list, list->next) etc rather than just having a destructor pull it out when its done). I was thinking of adding a second set of list helpers to facilitate maintaining a list in this way.14:44
Keybuksure, that's more like how nih_list_entry works, no?14:45
sadmac2hm?14:45
* sadmac2 pulls a libnih tree onto his work machine14:45
KeybukNihList is embedded in structures14:47
KeybukNihListEntry is an NihList with a generic pointer14:47
Keybukwhere the list references the data contained in it14:47
sadmac2oic. that's an interesting way of doing it...14:48
sadmac2does its destructor unreference its target pointer then?14:48
Keybukyou could make it do that14:48
sadmac2then you could just use nih_free on the entry to remove from the list14:50
Keybukin theory the list/alloc stuff should be flexible enough to do it either way14:50
Keybukone of my other two libnih-using projects doesn't use the embedded list stuff14:51
Keybukbecause every object is in multiple lists14:51
sadmac2I've also had some ideas I'm sitting on about how to reduce nih_alloc's overhead and possibly make it a bit more flexible, but I'm still churning.14:52
sadmac2I have a thought that we could kill the parent/child lists and store a big adjacency matrix instead within a good sparse matrix data structure14:56
sadmac2might perform better too (cache lines hate linked lists)14:57
=== robbiew is now known as robbiew-afk
=== robbiew-afk is now known as robbiew
=== notting_ is now known as notting

Generated by irclog2html.py 2.7 by Marius Gedminas - find it at mg.pov.lt!