Mesa (master): util: remove the dummy field in mempool
Marek Olšák
mareko at kemper.freedesktop.org
Mon Jul 19 19:15:43 UTC 2010
Module: Mesa
Branch: master
Commit: fd03dd203f19301520d16de58552cc2fec5e6115
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=fd03dd203f19301520d16de58552cc2fec5e6115
Author: Marek Olšák <maraeo at gmail.com>
Date: Mon Jul 19 18:08:53 2010 +0200
util: remove the dummy field in mempool
It should allocate less memory now.
---
src/gallium/auxiliary/util/u_mempool.c | 13 ++++---------
src/gallium/auxiliary/util/u_mempool.h | 5 -----
2 files changed, 4 insertions(+), 14 deletions(-)
diff --git a/src/gallium/auxiliary/util/u_mempool.c b/src/gallium/auxiliary/util/u_mempool.c
index c4bb265..0ce4b6c 100644
--- a/src/gallium/auxiliary/util/u_mempool.c
+++ b/src/gallium/auxiliary/util/u_mempool.c
@@ -30,8 +30,6 @@
#define UTIL_MEMPOOL_MAGIC 0xcafe4321
-struct util_mempool_block_body { char dummy; };
-
/* The block is either allocated memory or free space. */
struct util_mempool_block {
/* The header. */
@@ -40,9 +38,6 @@ struct util_mempool_block {
intptr_t magic;
- /* The block begins here. */
- struct util_mempool_block_body body;
-
/* Memory after the last member is dedicated to the block itself.
* The allocated size is always larger than this structure. */
};
@@ -52,7 +47,8 @@ util_mempool_get_block(struct util_mempool *pool,
struct util_mempool_page *page, unsigned index)
{
return (struct util_mempool_block*)
- ((uint8_t*)&page->body + (pool->block_size * index));
+ ((uint8_t*)page + sizeof(struct util_mempool_page) +
+ (pool->block_size * index));
}
static void util_mempool_add_new_page(struct util_mempool *pool)
@@ -92,15 +88,14 @@ static void *util_mempool_malloc_st(struct util_mempool *pool)
assert(block->magic == UTIL_MEMPOOL_MAGIC);
pool->first_free = block->next_free;
- return &block->body;
+ return (uint8_t*)block + sizeof(struct util_mempool_block);
}
static void util_mempool_free_st(struct util_mempool *pool, void *ptr)
{
- struct util_mempool_block dummy;
struct util_mempool_block *block =
(struct util_mempool_block*)
- ((uint8_t*)ptr - ((uint8_t*)&dummy.body - (uint8_t*)&dummy));
+ ((uint8_t*)ptr - sizeof(struct util_mempool_block));
assert(block->magic == UTIL_MEMPOOL_MAGIC);
block->next_free = pool->first_free;
diff --git a/src/gallium/auxiliary/util/u_mempool.h b/src/gallium/auxiliary/util/u_mempool.h
index c96f9b6..a5b5d6a 100644
--- a/src/gallium/auxiliary/util/u_mempool.h
+++ b/src/gallium/auxiliary/util/u_mempool.h
@@ -43,16 +43,11 @@ enum util_mempool_threading {
UTIL_MEMPOOL_MULTITHREADED = TRUE
};
-struct util_mempool_page_body { char dummy; };
-
/* The page is an array of blocks (allocations). */
struct util_mempool_page {
/* The header (linked-list pointers). */
struct util_mempool_page *prev, *next;
- /* The page begins here. */
- struct util_mempool_page_body body;
-
/* Memory after the last member is dedicated to the page itself.
* The allocated size is always larger than this structure. */
};
More information about the mesa-commit
mailing list