mempool: add a zeroing alloc function

Add mempool_alloc0_tile(). It's like mempool_alloc_tile(), but it
initializes the allocated tile's memory to zero.
This commit is contained in:
Michal Schmidt
2014-10-30 19:50:50 +01:00
parent b5de6d9842
commit 52fc5ce38c
2 changed files with 10 additions and 0 deletions
+9
View File
@@ -74,6 +74,15 @@ void* mempool_alloc_tile(struct mempool *mp) {
return ((uint8_t*) mp->first_pool) + ALIGN(sizeof(struct pool)) + i*mp->tile_size;
}
void* mempool_alloc0_tile(struct mempool *mp) {
void *p;
p = mempool_alloc_tile(mp);
if (p)
memzero(p, mp->tile_size);
return p;
}
void mempool_free_tile(struct mempool *mp, void *p) {
* (void**) p = mp->freelist;
mp->freelist = p;
+1
View File
@@ -34,6 +34,7 @@ struct mempool {
};
void* mempool_alloc_tile(struct mempool *mp);
void* mempool_alloc0_tile(struct mempool *mp);
void mempool_free_tile(struct mempool *mp, void *p);
#define DEFINE_MEMPOOL(pool_name, tile_type, alloc_at_least) \