test_sballoc: comparison testing vs. palloc
authorRobert Haas <rhaas@postgresql.org>
Wed, 26 Mar 2014 00:07:19 +0000 (17:07 -0700)
committerRobert Haas <rhaas@postgresql.org>
Wed, 26 Mar 2014 00:07:19 +0000 (17:07 -0700)
contrib/test_sballoc/test_sballoc--1.0.sql
contrib/test_sballoc/test_sballoc.c

index 02ae0032af113ef02f4b8f4a140be5a31e8f8dbc..97e48d3e52859ea9d22d98e7a989bc554490873a 100644 (file)
@@ -6,3 +6,7 @@
 CREATE FUNCTION alloc(size pg_catalog.int8, count pg_catalog.int8)
     RETURNS pg_catalog.void
        AS 'MODULE_PATHNAME' LANGUAGE C STRICT;
+
+CREATE FUNCTION alloc_with_palloc(size pg_catalog.int8, count pg_catalog.int8)
+    RETURNS pg_catalog.void
+       AS 'MODULE_PATHNAME' LANGUAGE C STRICT;
index 81f1a5b9512b0dc7f0b1a8c56b57bce1f358e59c..2357625084fb88d6a9b0e2d8e0b1c3d455c639b4 100644 (file)
 #include "postgres.h"
 
 #include "fmgr.h"
+#include "utils/memutils.h"
 #include "utils/sb_alloc.h"
 
 PG_MODULE_MAGIC;
 PG_FUNCTION_INFO_V1(alloc);
+PG_FUNCTION_INFO_V1(alloc_with_palloc);
 
 Datum          alloc(PG_FUNCTION_ARGS);
+Datum          alloc_with_palloc(PG_FUNCTION_ARGS);
 
 Datum
 alloc(PG_FUNCTION_ARGS)
@@ -35,3 +38,22 @@ alloc(PG_FUNCTION_ARGS)
 
        PG_RETURN_VOID();
 }
+
+Datum
+alloc_with_palloc(PG_FUNCTION_ARGS)
+{
+       int64 size = PG_GETARG_INT64(0);
+       int64 count = PG_GETARG_INT64(1);
+       int64 i;
+       MemoryContext context;
+
+       context = AllocSetContextCreate(CurrentMemoryContext,
+                                                                   "alloc_with_palloc test",
+                                                                   ALLOCSET_DEFAULT_MINSIZE,
+                                                                   ALLOCSET_DEFAULT_INITSIZE,
+                                                                   ALLOCSET_DEFAULT_MAXSIZE);
+       for (i = 0; i < count; ++i)
+               (void) MemoryContextAlloc(context, size);
+
+       PG_RETURN_VOID();
+}