summaryrefslogtreecommitdiff
path: root/source3/lib/talloc/testsuite.c
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2008-01-05 18:26:54 +0100
committerJeremy Allison <jra@samba.org>2008-01-09 17:05:19 -0800
commit1ed4fcb271b7885c274bd88bafed8116779d8eb6 (patch)
tree11a2bf2be3acbd22e866abdf3001746bf69ba80d /source3/lib/talloc/testsuite.c
parent6a1022288217304ebf4f3a3e59a1efa472ff2c5b (diff)
downloadsamba-1ed4fcb271b7885c274bd88bafed8116779d8eb6.tar.gz
samba-1ed4fcb271b7885c274bd88bafed8116779d8eb6.tar.bz2
samba-1ed4fcb271b7885c274bd88bafed8116779d8eb6.zip
Implement talloc_pool()
A talloc pool is a chunk of memory that can be used as a context for further talloc calls. Allocations with the pool as the parent just chew from that memory by incrementing a pointer. If the talloc pool is full, then we fall back to the normal system-level malloc(3) to get memory. The use case for talloc pools is the transient memory that is used for handling a single SMB request. Incrementing a pointer will be way faster than any malloc implementation. There is a downside of this: If you use talloc_steal() to move something out of the pool, the whole pool memory is kept around until the last object inside the pool is freed. So if you talloc_free() the pool, it might happen that the memory is freed later. So don't hang anything off a talloc pool that should live long. Volker (This used to be commit 287e29d988813007eeebc0c2bef3b46ab8bedee9)
Diffstat (limited to 'source3/lib/talloc/testsuite.c')
-rw-r--r--source3/lib/talloc/testsuite.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/source3/lib/talloc/testsuite.c b/source3/lib/talloc/testsuite.c
index e16c91f8b9..fedbda95aa 100644
--- a/source3/lib/talloc/testsuite.c
+++ b/source3/lib/talloc/testsuite.c
@@ -813,6 +813,25 @@ static bool test_speed(void)
talloc_free(ctx);
+ ctx = talloc_pool(NULL, 1024);
+
+ tv = timeval_current();
+ count = 0;
+ do {
+ void *p1, *p2, *p3;
+ for (i=0;i<loop;i++) {
+ p1 = talloc_size(ctx, loop % 100);
+ p2 = talloc_strdup(p1, "foo bar");
+ p3 = talloc_size(p1, 300);
+ talloc_free_children(ctx);
+ }
+ count += 3 * loop;
+ } while (timeval_elapsed(&tv) < 5.0);
+
+ talloc_free(ctx);
+
+ fprintf(stderr, "talloc_pool: %.0f ops/sec\n", count/timeval_elapsed(&tv));
+
tv = timeval_current();
count = 0;
do {
@@ -1066,6 +1085,23 @@ static bool test_autofree(void)
return true;
}
+static bool test_pool(void)
+{
+ void *pool;
+ void *p1, *p2, *p3, *p4;
+
+ pool = talloc_pool(NULL, 1024);
+
+ p1 = talloc_size(pool, 80);
+ p2 = talloc_size(pool, 20);
+ p3 = talloc_size(p1, 50);
+ p4 = talloc_size(p3, 1000);
+
+ talloc_free(pool);
+
+ return true;
+}
+
struct torture_context;
bool torture_local_talloc(struct torture_context *tctx)
{
@@ -1094,6 +1130,7 @@ bool torture_local_talloc(struct torture_context *tctx)
ret &= test_free_parent_deny_child();
ret &= test_talloc_ptrtype();
ret &= test_talloc_free_in_destructor();
+ ret &= test_pool();
if (ret) {
ret &= test_speed();