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

sadmacKeybuk: how was your flight?14:05
Keybuksadmac: short and uneventful14:49
Keybukjust the way I like them ;)14:49
sadmacKeybuk: sweet14:49
sadmacKeybuk: so after hacking n-ary event operators together, I'm getting a segfault inside nih_ref14:49
sadmacKeybuk: specifically in a call to nih_list_add_after14:50
Keybukis the pointer freed?14:51
sadmacKeybuk: I don't believe so. If so its an error outside my code.14:52
sadmacor maybe not... yeah it could be in the parse_job changes14:52
Keybukone of the obvious issues with nih_alloc14:55
Keybuk x = nih_alloc (NULL, ...)14:55
Keybuk nih_ref (y, x)14:56
Keybuk nih_unref (y, x)14:56
Keybuk // x is now free14:56
sadmacKeybuk: it also bugs me that you have to declare nih_local in a certain place or you get a leak14:56
sadmacnih_local int *foo; while {} vs while {nih_local int *foo }14:57
sadmacKeybuk: I have a solution for that. I would propose a macro that would create a local /parent/ rather than a local object. So when you did locally scoped allocations, you'd just give them that parent and they'd all go away at once.14:58
sadmacits a bit harder to screw up, and its not mutually exclusive with nih_local so we can keep bot.14:58
sadmac*both14:58
Keybuknot sure I follow15:01
sadmacKeybuk: so where you had this:15:01
sadmacnih_local obj *foo = nih_alloc (null, sizeof obj);15:02
sadmacKeybuk: you'd have this15:02
Keybukyes, you can do that ;)15:02
sadmacNIH_DECLARE_LOCAL_ANCHOR (anchor)15:02
Keybuknih_local void *foo = nih_alloc (NULL, 0);15:02
sadmacobj *foo = nih_alloc (anchor, sizeof obj);15:03
sadmacKeybuk: nih_alloc doesn't assert there?15:03
sadmacKeybuk: because otherwise yes, that'd pretty much be it15:03
sadmacKeybuk: though I'd recommend the type be struct dummy * so it screams a bit if you try to use it as an object.15:04
Keybuknot that I know of15:10
sadmacKeybuk: well that works out nicely then15:11
Keybukthough I don't see that that helps you15:14
sadmacKeybuk: it makes it a bit harder to lose objects15:17
sadmacKeybuk: anything that has that as a parent at the end of the function /will/ get an unref15:18
sadmacKeybuk: regardless of whether its address is stored at a particular local pointer.15:18
sadmacKeybuk: it also offers a performance advantage15:21
sadmacNIH_DECLARE_LOCAL_ANCHOR (anchor)15:21
sadmacwhile (...) { /* use anchor for allocating */ }15:21
sadmacreturn;15:22
sadmacthe stuff the loop created isn't freed til return. The loop now never passes through allocation code. The program gets faster.15:22
sadmac*never passes through free code15:23
Keybukwhy is that different than the alternative?15:25
Keybukthe loop can instead consume large amounts of memory15:25
sadmacKeybuk: unlikely for most use patterns. Deferring garbage collection should be a big win in 99.9% of cases. The other way is still there. Furthermore, the old C maxim that variable declarations belong at the top of the function (and that's not a crazy assertion whether you agree or not) is no longer punished with a memory leak.15:27
sadmacKeybuk: and what's more, you no longer treat objects specially based on what variables they're held in. Less semantic confusion15:28
Keybukbut why can't you put them in the while loop?15:29
sadmacKeybuk: you can, its just gross.15:30
Keybuksure15:32
Keybukwhich is why I tend to attach them to something else outside it15:32
sadmacnot following15:37
Keybukwell, I do what you do in those situations15:37
Keybukhave something at the top-level of the function and attach things to it15:38
sadmacmakes sense15:38
Milan-BVKeybuk: hi!19:10

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