/dev/tomkiewicz/new-smileys: cf4d3e9df570: Memory pool: make it ...

Tomasz Wasilczyk twasilczyk at pidgin.im
Fri Apr 4 17:42:19 EDT 2014


Changeset: cf4d3e9df570a90654369f29c84adf9da354427e
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2014-04-04 23:42 +0200
Branch:	 default
URL: https://hg.pidgin.im/dev/tomkiewicz/new-smileys/rev/cf4d3e9df570

Description:

Memory pool: make it possible to disable it

diffstat:

 libpurple/memorypool.c |  17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diffs (53 lines):

diff --git a/libpurple/memorypool.c b/libpurple/memorypool.c
--- a/libpurple/memorypool.c
+++ b/libpurple/memorypool.c
@@ -33,11 +33,13 @@
 	(gpointer)((((guintptr)(pointer) - 1) / (padding) + 1) * padding)
 
 #define PURPLE_MEMORY_POOL_DEFAULT_BLOCK_SIZE 1024
+#define PURPLE_MEMORY_POOL_DISABLED FALSE
 
 typedef struct _PurpleMemoryPoolBlock PurpleMemoryPoolBlock;
 
 typedef struct
 {
+	gboolean disabled;
 	gulong block_size;
 
 	PurpleMemoryPoolBlock *first_block;
@@ -104,6 +106,11 @@ purple_memory_pool_alloc_impl(PurpleMemo
 
 	g_return_val_if_fail(priv != NULL, NULL);
 
+	if (priv->disabled) {
+		/* XXX: this may cause some leaks */
+		return g_try_malloc(size);
+	}
+
 	g_return_val_if_fail(alignment <= PURPLE_MEMORY_POOL_BLOCK_PADDING, NULL);
 	g_warn_if_fail(alignment >= 1);
 	if (alignment < 1)
@@ -262,6 +269,15 @@ purple_memory_pool_new(void)
 }
 
 static void
+purple_memory_pool_init(GTypeInstance *instance, gpointer klass)
+{
+	PurpleMemoryPool *pool = PURPLE_MEMORY_POOL(instance);
+	PurpleMemoryPoolPrivate *priv = PURPLE_MEMORY_POOL_GET_PRIVATE(pool);
+
+	priv->disabled = PURPLE_MEMORY_POOL_DISABLED;
+}
+
+static void
 purple_memory_pool_finalize(GObject *obj)
 {
 	purple_memory_pool_cleanup(PURPLE_MEMORY_POOL(obj));
@@ -335,6 +351,7 @@ purple_memory_pool_get_type(void)
 			.class_size = sizeof(PurpleMemoryPoolClass),
 			.class_init = (GClassInitFunc)purple_memory_pool_class_init,
 			.instance_size = sizeof(PurpleMemoryPool),
+			.instance_init = (GInstanceInitFunc)purple_memory_pool_init
 		};
 
 		type = g_type_register_static(G_TYPE_OBJECT,



More information about the Commits mailing list