[Gegl-developer] memory management

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

 



I was wondering if there is some kind of memory management policy in gegl. (e.g. should functions return memory that you need to free? Do functions ever free memory you give them?). I looked but didn't find anything codified.

I am assuming this hasn't been touched on much. (This is all motivated by the surprise I felt when I noticed that gegl_image_iterator_get_color_channels returned an array that needed to be freed.

One policy is to enforce a strict system. I am ok with this. However I like this second idea more, so I am going to talk about it.

One of the gtk developers (I can't remember his name at the moment, and I lost the reference I got this from) suggested using a function naming scheme to specify "ownership" of pointers returned by functions as an alterative to the typical get/set nameing scheme.

For return values that are pointers (e.g. certain get functions and object factories):

Use "get" if the caller must free memory (suggesting that that you are getting something that belongs to you) and "peek" if the caller is not supposed to free the memory (suggesting that you may look, but it is not yours). If it is a gobject, then "get" will return the object to you with the reference count already increased (possibly removing a reference in the process), and peek will not increase the reference count before returning the object.

the gtk developer suggested steal instead of get. I think that get and peek are better descriptions than steal and peek because a function may allocate memory to give to you, thus are aren't really stealing something that is freely given, but if someone else prefers steal, speak up.


For arguments to functions that are pointers (e.g. certain set functions):

The gtk developer didn't have a good idea for a function naming scheme in this case. I suggest: give as the opposite of get and show as the opposite of peek. If you give memory you must not free it. if you give an object, then it will behave as though it was dereferenced for you. If you show a piece of memory, you are still responsible for freeing it. If you show an object, you are still responsible for unrefing the object.

--
Dan


[Index of Archives]     [Yosemite News]     [Yosemite Photos]     [gtk]     [GIMP Users]     [KDE]     [Gimp's Home]     [Gimp on Windows]     [Steve's Art]

  Powered by Linux