Use the slice allocator if GLIB >= 2,10,0 as suggested by Anders Broman

svn path=/trunk/; revision=29434
This commit is contained in:
Kovarththanan Rajaratnam 2009-08-15 13:24:59 +00:00
parent 623db2e71e
commit aed905a6c9
1 changed files with 17 additions and 0 deletions

View File

@ -58,23 +58,32 @@ ensure_contiguous_no_exception(tvbuff_t *tvb, gint offset, gint length,
static const guint8*
ensure_contiguous(tvbuff_t *tvb, gint offset, gint length);
#if GLIB_CHECK_VERSION(2,10,0)
#else
/* We dole out tvbuff's from this memchunk. */
static GMemChunk *tvbuff_mem_chunk = NULL;
#endif
void
tvbuff_init(void)
{
#if GLIB_CHECK_VERSION(2,10,0)
#else
if (!tvbuff_mem_chunk)
tvbuff_mem_chunk = g_mem_chunk_create(tvbuff_t, 20, G_ALLOC_AND_FREE);
#endif
}
void
tvbuff_cleanup(void)
{
#if GLIB_CHECK_VERSION(2,10,0)
#else
if (tvbuff_mem_chunk)
g_mem_chunk_destroy(tvbuff_mem_chunk);
tvbuff_mem_chunk = NULL;
#endif
}
static void
@ -125,7 +134,11 @@ tvb_new(tvbuff_type type)
{
tvbuff_t *tvb;
#if GLIB_CHECK_VERSION(2,10,0)
tvb = g_slice_new(tvbuff_t);
#else
tvb = g_chunk_new(tvbuff_t, tvbuff_mem_chunk);
#endif
tvb_init(tvb, type);
@ -185,7 +198,11 @@ tvb_free(tvbuff_t* tvb)
g_slist_free(tvb->used_in);
}
#if GLIB_CHECK_VERSION(2,10,0)
g_slice_free(tvbuff_t, tvb);
#else
g_chunk_free(tvb, tvbuff_mem_chunk);
#endif
}
}