From 4d5479406d28602211435e7f31876f70891102f4 Mon Sep 17 00:00:00 2001 From: cedric Date: Tue, 21 Sep 2010 15:18:15 +0000 Subject: [PATCH] * eina: call malloc only when content is requested from the pool. git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/eina@52543 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/modules/mp/one_big/eina_one_big.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/modules/mp/one_big/eina_one_big.c b/src/modules/mp/one_big/eina_one_big.c index 27bfe83..1b810e6 100644 --- a/src/modules/mp/one_big/eina_one_big.c +++ b/src/modules/mp/one_big/eina_one_big.c @@ -94,6 +94,16 @@ eina_one_big_malloc(void *data, __UNUSED__ unsigned int size) goto on_exit; } + if (!pool->base) + { + pool->base = malloc(pool->item_size * pool->max); + if (!pool->base) + { + eina_error_set(EINA_ERROR_OUT_OF_MEMORY); + goto retry_smaller; + } + } + if (pool->served < pool->max) { mem = pool->base + (pool->served++ *pool->item_size); @@ -101,7 +111,8 @@ eina_one_big_malloc(void *data, __UNUSED__ unsigned int size) goto on_exit; } - eina_error_set(0); + retry_smaller: + eina_error_set(0); mem = malloc(pool->item_size); if (!mem) eina_error_set(EINA_ERROR_OUT_OF_MEMORY); @@ -187,13 +198,6 @@ eina_one_big_init(const char *context, memcpy((char *)pool->name, context, length); } - pool->base = malloc(pool->item_size * pool->max); - if (!pool->base) - { - free(pool); - return NULL; - } - #ifdef EFL_HAVE_THREADS # ifdef EFL_HAVE_POSIX_THREADS pthread_mutex_init(&pool->mutex, NULL); -- 2.7.4