]> git.ipfire.org Git - thirdparty/bird.git/blobdiff - lib/resource.h
Filter test: typo fix
[thirdparty/bird.git] / lib / resource.h
index 1491fde7ca3d86055601058ff22b0e0194e136a2..1a62d3891b5a0297330d0f94198da5443b7be283 100644 (file)
@@ -25,8 +25,13 @@ struct resclass {
   unsigned size;                       /* Standard size of single resource */
   void (*free)(resource *);            /* Freeing function */
   void (*dump)(resource *);            /* Dump to debug output */
+  resource *(*lookup)(resource *, unsigned long);      /* Look up address (only for debugging) */
+  size_t (*memsize)(resource *);       /* Return size of memory used by the resource, may be NULL */
 };
 
+/* Estimate of system allocator overhead per item, for memory consumtion stats */
+#define ALLOC_OVERHEAD         8
+
 /* Generic resource manipulation */
 
 typedef struct pool pool;
@@ -35,6 +40,9 @@ void resource_init(void);
 pool *rp_new(pool *, char *);          /* Create new pool */
 void rfree(void *);                    /* Free single resource */
 void rdump(void *);                    /* Dump to debug output */
+size_t rmemsize(void *res);            /* Return size of memory used by the resource */
+void rlookup(unsigned long);           /* Look up address (only for debugging) */
+void rmove(void *, pool *);            /* Move to a different pool */
 
 void *ralloc(pool *, struct resclass *);
 
@@ -44,6 +52,7 @@ extern pool root_pool;
 
 void *mb_alloc(pool *, unsigned size);
 void *mb_allocz(pool *, unsigned size);
+void *mb_realloc(void *m, unsigned size);
 void mb_free(void *);
 
 /* Memory pools with linear allocation */
@@ -69,15 +78,19 @@ void sl_free(slab *, void *);
  * outside resource manager and possibly sysdep code.
  */
 
+void buffer_realloc(void **buf, unsigned *size, unsigned need, unsigned item_size);
+
+
 #ifdef HAVE_LIBDMALLOC
 /*
  * The standard dmalloc macros tend to produce lots of namespace
- * conflicts and we use only xmalloc and xfree, so we can define
- * the stubs ourselves.
+ * conflicts and we use only xmalloc, xrealloc and xfree, so we
+ * can define the stubs ourselves.
  */
 #define DMALLOC_DISABLE
 #include <dmalloc.h>
 #define xmalloc(size) _xmalloc_leap(__FILE__, __LINE__, size)
+#define xrealloc(size) _xrealloc_leap(__FILE__, __LINE__, size)
 #define xfree(ptr) _xfree_leap(__FILE__, __LINE__, ptr)
 #else
 /*
@@ -86,8 +99,11 @@ void sl_free(slab *, void *);
  * the renaming.
  */
 #define xmalloc bird_xmalloc
+#define xrealloc bird_xrealloc
 void *xmalloc(unsigned);
+void *xrealloc(void *, unsigned);
 #define xfree(x) free(x)
 #endif
 
 #endif
+