From d75345abec3e0395e030fcac25fcf9a32cea0246 Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Tue, 25 Mar 2014 17:07:19 -0700 Subject: [PATCH] test_sballoc: comparison testing vs. palloc --- contrib/test_sballoc/test_sballoc--1.0.sql | 4 ++++ contrib/test_sballoc/test_sballoc.c | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/contrib/test_sballoc/test_sballoc--1.0.sql b/contrib/test_sballoc/test_sballoc--1.0.sql index 02ae0032af..97e48d3e52 100644 --- a/contrib/test_sballoc/test_sballoc--1.0.sql +++ b/contrib/test_sballoc/test_sballoc--1.0.sql @@ -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; diff --git a/contrib/test_sballoc/test_sballoc.c b/contrib/test_sballoc/test_sballoc.c index 81f1a5b951..2357625084 100644 --- a/contrib/test_sballoc/test_sballoc.c +++ b/contrib/test_sballoc/test_sballoc.c @@ -14,12 +14,15 @@ #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(); +} -- 2.39.5