r6645: Add talloc_get_size() function.
authorSimo Sorce <idra@samba.org>
Sat, 7 May 2005 15:22:45 +0000 (15:22 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:16:32 +0000 (13:16 -0500)
Sometimes it is usefull to know this data.

Simo.
(This used to be commit df401847827ef660d8b9d55af9b27bb85bad6b5f)

source4/lib/talloc/talloc.c
source4/lib/talloc/talloc.h
source4/lib/talloc/talloc_guide.txt

index da3a2300b0af014430078632a7e71528c67c4c06..248af6ea3eef8360296eaf0c3410122146095563 100644 (file)
@@ -1082,3 +1082,13 @@ void *talloc_autofree_context(void)
 }
 
 
+size_t talloc_get_size(const void *context) {
+       struct talloc_chunk *tc;
+
+       if (context == NULL)
+               return 0;
+
+       tc = talloc_chunk_from_ptr(context);
+
+       return tc->size;
+}
index 8b448f63c55ed3f466eedae84dd57699c8370c3f..ab549cf624ab10049b8b23f15af6471fe5d322e7 100644 (file)
@@ -126,6 +126,7 @@ void *_talloc_zero_array(const void *ctx, size_t el_size, unsigned count, const
 void *_talloc_realloc_array(const void *ctx, void *ptr, size_t el_size, unsigned count, const char *name);
 void *talloc_realloc_fn(const void *context, void *ptr, size_t size);
 void *talloc_autofree_context(void);
+size_t talloc_get_size(const void *ctx);
 
 #endif
 
index 55349ec05b8180f48d1f7bf5f85a18d288596d22..c23ac77cad72ab9265ee5af5bf5edbc1e6800380 100644 (file)
@@ -559,3 +559,11 @@ talloc_get_type() to do type checking on void* pointers.
 
 It is equivalent to this:
    talloc_set_name_const(ptr, #type)
+
+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
+talloc_get_size(const void *ctx);
+
+This function lets you know the amount of memory alloced so far by
+this context. It does NOT account for subcontext memory.
+This can be used to calculate the size of an array.
+