/srv/irclogs.ubuntu.com/2008/01/02/#upstart.txt

ion_keybuk: Have you had a chance to waste cycles with my email yet? :-)15:47
Keybuknot even read it yet15:50
Keybukonly returned from holiday this morning15:50
Keybukand haven't done e-mail catch-up15:50
ion_Alright.16:01
ion_No hurry.16:01
KeybukI originally wrote nih_alloc with ref-counting16:02
KeybukI forget why I removed it16:02
ion_keybuk: Do you think you’ll still be able to take a look at my commit today? :-)21:46
Keybukion_: why is it a uint32_t ?23:30
Keybukunless you have specific need for a 32-bit type, shouldn't that just be "unsigned int" ?23:31
ion_Heh, i just thought “whatever, uint32_t is shorter to type and it’s not as if it’s too small for a refcount”. :-P23:33
Keybukit's reasonably good practice to avoid the "fixed length" types unless you really want a fixed length23:34
ion_Ok, i’ll keep that in mind from now on.23:34
Keybukah, now I remember why I didn't go with reference counting23:38
Keybukit made the world tricky when dealing with parents23:38
Keybukif you return objects with a ref count as 1 when parent = NULL23:38
Keybukand the parent holds a ref on the object23:39
Keybukthen surely the returned object has to have a ref count of 1 when parent != NULL (ie. the parent)23:39
Keybukwhich didn't actually do what you want23:39
Keybukso you had to have the parents *not* reference the object23:39
ion_Oh, perhaps i forgot to document it, but the refcount is increased when it’s added to a parent.23:39
Keybuksince that's actually what you are after23:39
Keybukbut then how do you deal with a child object being referenced when its parent is freed?23:40
Keybuksorry, not explaining well23:40
Amaranthhow can a child not have a parent? :)23:40
Amaranthdunno what exactly you're talking about but i'm thinking the child would get a new parent?23:41
Keybuka = nih_new (NULL, void *);23:41
Keybukthat has a refcount of 123:41
Keybukour reference23:41
Amaranthright23:41
Keybukb = nih_new (a, void *);23:41
Keybukthat has a refcount of 223:41
Amaranthok23:41
Keybukour reference23:41
KeybukAND a reference by its parent23:42
Keybukif I do nih_unref (a) now, what happens to b?23:42
Amaranthit has a refcount of 1?23:42
ion_Its refcount drops to 123:42
Amaranthcan you still use b?23:42
Keybukso the object isn't freed when its parent is23:42
Amaranthnot if someone else is holding on to it, why would it be?23:43
Keybukthe whole point of using the hierarchial allocator is to forget about objects if they have a parent23:43
Keybukimagine23:43
Keybuk  a = nih_new (NULL, SomeStructure);23:43
ion_True...23:43
Keybuk a->title = nih_strdup (a, "foo");23:43
Keybuk a->description = nih_strdup (a, "some long description");23:43
Keybukif a reference is left open for me, I now have to remember to nih_unref those as well23:44
Keybukdoubling the length of code23:44
Amaranthbut wait, wouldn't a->title go away when a does?23:44
Keybukno23:44
Keybukbecause its refcount is 223:44
Keybuklosing its parent would only decrease it to 1, so it would stay23:44
Amaranthbut a is gone, how can a->title exist?23:44
Keybukthe alternative way would be the refcount of any returned object to always be 123:45
ion_Actually, what i’d like to have would be the possibility of adding a child to multiple parents – or rather “containers” – so that each one references the child once. But granted, that’s something completely different than using the parent to automatically free the kids.23:45
Keybukif its parent is NULL, then its 1 (yours)23:45
Keybukif the parent is non-NULL, then its 1 (the parent)23:45
Amaranthbut then you're not really doing refcounting23:45
Keybukbut then you can't unref the child yourself, since you don't have a reference :-)23:45
Keybukion_: sure23:45
Keybukthat's a refcounting allocator ;)23:45
Keybuknot a hierarchial one23:46
Keybukit'd be a good different allocator, but I don't think you can bolt it onto an h one23:46
ion_tss, the author of liblib (the “standard library” dovecot and icecap use) uses memory pools to implement the following:23:46
ion_foo_push (pool);23:46
ion_Allocate stuff using pool23:46
ion_foo_pop (pool); // Everything you allocated above is freed23:47
ion_But that solves a different problem.23:47
Keybukyeah, it's a bit like obstacks23:47
Amaranththat sounds like what nih has now23:47
Keybukhe wrote a great paper on why he did it that way, instead of just using alloca23:47
ion_I wonder whether i’ll end up NIHing my own “standard library” that is based on refcounting, since it would fit my application quite well... :-P23:48
Keybukinterestingly, talloc (a description of which is what nih_alloc is roughly based on) does have ref-counting23:48
ion_It would resemble libnih *a lot* since i quite like libnih, though, so i’d rather avoid duplication of effort.23:49
ion_Perhaps there’s a way to implement refcounting without breaking the hierarchical allocation. I’ll have to think about it when my brain is less exhausted.23:50
Keybukgrab the samba source and look though source/lib/talloc.c and work out how Tridge does it? :p23:50
ion_Ok, i’ll take a look. :-)23:51
KeybukI think other objects can hold secondary references on an object23:51
Keybukand if the parent is freed, the object is reparented to the first secondary reference23:52
Keybuk"god parents" if you like23:52
Keybuk a = nih_new (NULL, void *);23:52
ion_A random thought: if nih_new is called with a parent, it’s still initialized with a refcount of one and you’re forbidden from calling nih_unref on the resulting object. Would that work?23:52
Keybuk b = nih_new (a, void *);23:52
Keybuk c = nih_new (NULL, void *);23:52
Keybuk nih_alloc_reference (c, b);23:52
Keybuk nih_free (a);23:52
Keybuk /* parent of b is now c */23:52
Keybukion_: then you can't free the object independently later since you don't hold a ref on it23:53
Keybuk(not without breaking ref counting semantics anyway)23:53
ion_For own storage, you could then nih_ref it. :-P But yeah, that would be cumbersome.23:54
Keybukthe god parent thing might work quite nicely though23:54
KeybukI don't know what you want the ref counting for?23:55
Amaranththis reminds me of GInitiallyUnowned23:56
Amaranthi mean, in this case it's initially owned by the parent but it's the same concept23:57
Amaranthyou don't want the creator to have a reference23:57
ion_For instance, in an OpenGL engine i’m working on, a texture object can be attached to a number of mesh objects. I want the meshes to reference the texture, and unref it when they’re being freed.23:59

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