]> mj.ucw.cz Git - libucw.git/commitdiff
Implemented {mp,ep}_total_size().
authorPavel Charvat <pchar@ucw.cz>
Tue, 8 Jul 2008 06:23:16 +0000 (08:23 +0200)
committerPavel Charvat <pchar@ucw.cz>
Tue, 8 Jul 2008 06:23:16 +0000 (08:23 +0200)
lib/eltpool.c
lib/eltpool.h
lib/mempool.c
lib/mempool.h

index f82de845e56b925a0c27301e504350313b0d9053..b32843fc6ed360638094346db600c2aaba722867 100644 (file)
@@ -60,9 +60,16 @@ ep_alloc_slow(struct eltpool *pool)
     }
   ch->next = pool->first_chunk;
   pool->first_chunk = ch;
+  pool->num_chunks++;
   return p;
 }
 
+u64
+ep_total_size(struct eltpool *pool)
+{
+  return (u64)pool->num_chunks * pool->chunk_size + sizeof(*pool);
+}
+
 #ifdef TEST
 
 #include <stdio.h>
index 7e295fb7b0d4bbaa71acb90f42fc4b386a4993cc..795a45e997dc7957519fd5118ffb852b2ad93b07 100644 (file)
@@ -17,6 +17,7 @@ struct eltpool {
   uns chunk_size;
   uns elts_per_chunk;
   uns num_allocated;           // Just for debugging
+  uns num_chunks;
 };
 
 struct eltpool_chunk {
@@ -31,6 +32,7 @@ struct eltpool_free {
 struct eltpool *ep_new(uns elt_size, uns elts_per_chunk);
 void ep_delete(struct eltpool *pool);
 void *ep_alloc_slow(struct eltpool *pool);
+u64 ep_total_size(struct eltpool *pool);
 
 static inline void *
 ep_alloc(struct eltpool *pool)
index 658f53845a99b73605d1fc6a3475318e82793056..fee77f03496d4c6e48d9637f55b3ff255223f208 100644 (file)
@@ -168,6 +168,14 @@ mp_stats(struct mempool *pool, struct mempool_stats *stats)
   mp_stats_chain(pool->unused, stats, 2);
 }
 
+u64
+mp_total_size(struct mempool *pool)
+{
+  struct mempool_stats stats;
+  mp_stats(pool, &stats);
+  return stats.total_size;
+}
+
 void *
 mp_alloc_internal(struct mempool *pool, uns size)
 {
index c53423abc1130a1f8f4600c4535c3e543e4697cd..d8602410fd70b310ca61436672a3d7d3ce88dccb 100644 (file)
@@ -27,7 +27,7 @@ struct mempool {
 
 /* Statistics (see mp_stats()) */
 struct mempool_stats {
-  uns total_size;                      /* Real allocated size in bytes */
+  u64 total_size;                      /* Real allocated size in bytes */
   uns chain_count[3];                  /* Number of allocated chunks in small/big/unused chains */
   uns chain_size[3];                   /* Size of allocated chunks in small/big/unused chains */
 };
@@ -46,6 +46,7 @@ void mp_flush(struct mempool *pool);
 
 /* Compute some statistics for debug purposes. See the definition of the mempool_stats structure. */
 void mp_stats(struct mempool *pool, struct mempool_stats *stats);
+u64 mp_total_size(struct mempool *pool);
 
 
 /*** Allocation routines ***/