PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
fe_memutils.h
Go to the documentation of this file.
1 /*
2  * fe_memutils.h
3  * memory management support for frontend code
4  *
5  * Copyright (c) 2003-2017, PostgreSQL Global Development Group
6  *
7  * src/include/common/fe_memutils.h
8  */
9 #ifndef FE_MEMUTILS_H
10 #define FE_MEMUTILS_H
11 
12 /*
13  * Flags for pg_malloc_extended and palloc_extended, deliberately named
14  * the same as the backend flags.
15  */
16 #define MCXT_ALLOC_HUGE 0x01 /* allow huge allocation (> 1 GB) not
17  * actually used for frontends */
18 #define MCXT_ALLOC_NO_OOM 0x02 /* no failure if out-of-memory */
19 #define MCXT_ALLOC_ZERO 0x04 /* zero allocated memory */
20 
21 /*
22  * "Safe" memory allocation functions --- these exit(1) on failure
23  * (except pg_malloc_extended with MCXT_ALLOC_NO_OOM)
24  */
25 extern char *pg_strdup(const char *in);
26 extern void *pg_malloc(size_t size);
27 extern void *pg_malloc0(size_t size);
28 extern void *pg_malloc_extended(size_t size, int flags);
29 extern void *pg_realloc(void *pointer, size_t size);
30 extern void pg_free(void *pointer);
31 
32 /* Equivalent functions, deliberately named the same as backend functions */
33 extern char *pstrdup(const char *in);
34 extern void *palloc(Size size);
35 extern void *palloc0(Size size);
36 extern void *palloc_extended(Size size, int flags);
37 extern void *repalloc(void *pointer, Size size);
38 extern void pfree(void *pointer);
39 
40 /* sprintf into a palloc'd buffer --- these are in psprintf.c */
41 extern char *psprintf(const char *fmt,...) pg_attribute_printf(1, 2);
42 extern size_t pvsnprintf(char *buf, size_t len, const char *fmt, va_list args) pg_attribute_printf(3, 0);
43 
44 #endif /* FE_MEMUTILS_H */
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
char * psprintf(const char *fmt,...) pg_attribute_printf(1
void * palloc(Size size)
Definition: mcxt.c:848
void pg_free(void *pointer)
Definition: fe_memutils.c:105
#define pg_attribute_printf(f, a)
Definition: c.h:627
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:962
char * pstrdup(const char *in)
Definition: mcxt.c:1076
static char * buf
Definition: pg_test_fsync.c:67
void * pg_malloc_extended(size_t size, int flags)
Definition: fe_memutils.c:59
char size_t pvsnprintf(char *buf, size_t len, const char *fmt, va_list args) pg_attribute_printf(3
void * palloc0(Size size)
Definition: mcxt.c:877
size_t Size
Definition: c.h:350
void * pg_realloc(void *pointer, size_t size)
Definition: fe_memutils.c:65
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
void pfree(void *pointer)
Definition: mcxt.c:949
void * palloc_extended(Size size, int flags)
Definition: mcxt.c:908