Re: RFC: glocal - automatically freeing memory when it goes out of scope



On 05/29/2012 05:36 PM, Colin Walters wrote:
On Sun, 2012-05-27 at 11:20 +0200, Mikkel Kamstrup Erlandsen wrote:

Attached a new version as a late update to this thread, but better
than nothing I hope :-) I still haven't gotten around to sticking it
in libegg (or even a bug). Sorry! I'll do that when I am more happy
with what I have.

"glocal_string" is really "glocal_free", or at least that's what
I called it in my version, because you can use it on anything
that you know can be freed with g_free(), which isn't just
strings.  For example, private structures.

Ah, of course. Makes a lot more sense.

  - Added glocal_defer(callback, arg): Calls @callback with @arg when
leaving the current scope

Hmm.  What's the use case for this one?

I use it for the automatic unlocking macros for example. Or to close a stream/fd, or to do manual profiling of hot spots - you just have one ifdef block at the top, and not littered all over the function at all return points, or if you're building some kind of message that you must always write() to a pipe before returning, etc.

Cheers,
Mikkel


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]