summaryrefslogtreecommitdiff
path: root/src/include/utils/palloc.h
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2002-12-16 16:22:46 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2002-12-16 16:22:46 +0000
commit88177f77b17ef478da1dbca9acb5e3a61b346613 (patch)
tree6aca48712e12bbdd7a7bab849dcaac3f25684e32 /src/include/utils/palloc.h
parente64c7feb2fd80c89d2220cbe9e026a031f34509c (diff)
downloadpostgresql-88177f77b17ef478da1dbca9acb5e3a61b346613.tar.gz
Code review for palloc0 patch --- avoid dangerous and unnecessary
practice of evaluating MemSet's arguments multiple times, except for the special case of newNode(), where we can assume the argument is a constant sizeof() operator. Also, add GetMemoryChunkContext() to mcxt.c's API, in preparation for fixing recent GEQO breakage.
Diffstat (limited to 'src/include/utils/palloc.h')
-rw-r--r--src/include/utils/palloc.h24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/include/utils/palloc.h b/src/include/utils/palloc.h
index 093764d5eb..7dabc52f31 100644
--- a/src/include/utils/palloc.h
+++ b/src/include/utils/palloc.h
@@ -21,7 +21,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: palloc.h,v 1.23 2002/11/13 00:37:06 momjian Exp $
+ * $Id: palloc.h,v 1.24 2002/12/16 16:22:46 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -46,15 +46,25 @@ extern DLLIMPORT MemoryContext CurrentMemoryContext;
* Fundamental memory-allocation operations (more are in utils/memutils.h)
*/
extern void *MemoryContextAlloc(MemoryContext context, Size size);
-extern void *MemoryContextAllocPalloc0(MemoryContext context, Size size);
+extern void *MemoryContextAllocZero(MemoryContext context, Size size);
+extern void *MemoryContextAllocZeroAligned(MemoryContext context, Size size);
#define palloc(sz) MemoryContextAlloc(CurrentMemoryContext, (sz))
-/* We assume palloc() is already int-aligned */
-#define palloc0(sz) \
- ( MemSetTest(0, (sz)) ? \
- MemoryContextAllocPalloc0(CurrentMemoryContext, (sz)) : \
- memset(palloc(sz), 0, (sz)))
+#define palloc0(sz) MemoryContextAllocZero(CurrentMemoryContext, (sz))
+
+/*
+ * The result of palloc() is always word-aligned, so we can skip testing
+ * alignment of the pointer when deciding which MemSet variant to use.
+ * Note that this variant does not offer any advantage, and should not be
+ * used, unless its "sz" argument is a compile-time constant; therefore, the
+ * issue that it evaluates the argument multiple times isn't a problem in
+ * practice.
+ */
+#define palloc0fast(sz) \
+ ( MemSetTest(0, sz) ? \
+ MemoryContextAllocZeroAligned(CurrentMemoryContext, sz) : \
+ MemoryContextAllocZero(CurrentMemoryContext, sz) )
extern void pfree(void *pointer);