summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
Diffstat (limited to 'source4')
-rw-r--r--source4/lib/talloc/talloc.c10
-rw-r--r--source4/lib/talloc/talloc.h1
-rw-r--r--source4/lib/talloc/talloc_guide.txt8
3 files changed, 19 insertions, 0 deletions
diff --git a/source4/lib/talloc/talloc.c b/source4/lib/talloc/talloc.c
index da3a2300b0..248af6ea3e 100644
--- a/source4/lib/talloc/talloc.c
+++ b/source4/lib/talloc/talloc.c
@@ -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;
+}
diff --git a/source4/lib/talloc/talloc.h b/source4/lib/talloc/talloc.h
index 8b448f63c5..ab549cf624 100644
--- a/source4/lib/talloc/talloc.h
+++ b/source4/lib/talloc/talloc.h
@@ -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
diff --git a/source4/lib/talloc/talloc_guide.txt b/source4/lib/talloc/talloc_guide.txt
index 55349ec05b..c23ac77cad 100644
--- a/source4/lib/talloc/talloc_guide.txt
+++ b/source4/lib/talloc/talloc_guide.txt
@@ -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.
+