g_slice considered awesome.
- From: Robert Love <rml novell com>
- To: networkmanager-list gnome org
- Subject: g_slice considered awesome.
- Date: Thu, 03 Aug 2006 20:33:42 -0400
Party people,
I did some preliminary testing[1] the other day with beaglefs[2], to
measure the performance gain or hit from using glib's new memory
slices[3].
In a workcase where many objects are created and freed[4], I measured a
sizable performance gain from memory slices over g_malloc. Even without
heavy thread usage of multiprocessors[5]. The glib API manual has this
to say:
For newly written code it is recommended to use the new g_slice
API instead of g_mallc() and friends, as long as objects are not
resized during their lifetime and the object size used at
allocation time is still available when freeing.
Essentially anywhere we use g_new() or g_malloc(sizeof(foo)), we should
switch to g_slice_new() and g_slice_free().
The caveat? Memory slices are only in glib 2.10 and later (2.12 is
current). We currently only require 2.6.
So we have, as I see it, four options:
1. Do nothing. In lieu, burn buildings and riot. Topple cars.
2. Require glib 2.10 or later and move all applicable memory
allocators to the super-cool memory slice API.
3. Put ifdef's in the code, checking for the glib version and
doing the appropriate thing. Cons: Ugly. Pros: Do not have to
introduce our own wrapper.
4. Introduce our own wrapper. Pros: Pretty. Cons: Another
wrapper. As a plus, it can be an inline function in a header,
at least.
I like #4 the most. We can do it in both branches, even. One nice
thing about #4 is that we can make our wrapper mirror the slice API and
we can do a mass find-and-replace and remove it once we do require glib
2.10.
I would be happy doing #2 in HEAD and #4 in the 0.6 branch. What would
others feel about requiring glib 2.10 in HEAD?
#4 would look like the following, in lib/nm-utils.h:
#define nm_alloc_new (__type__) do { \
#if GLIB_CHECK_VERSION(2,10,0)
g_slice_new (__type__); \
# else
g_new (__type__, 1); \
#endif
} while(0)
Assuming the preprocessor bastardization works. But you get the idea.
Comments?
Best,
Robert "Half Wolverine" Love
[1] Sorry, I don't have the results in a meaningful format. If I find
the time, I will retest and generate presentable data. Even better,
play on your own!
[2] http://www.kernel.org/pub/linux/kernel/people/rml/fuse/beaglefs/
[3] http://developer.gnome.org/doc/API/2.0/glib/glib-Memory-Slices.html
[4] The freeing being where g_slice shines, as it provides effectively
an uber-smart object cache / free-list.
[5] Another area where memory slices should shine.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]