1/*
2 * fe_memutils.h
3 * memory management support for frontend code
4 *
5 * Copyright (c) 2003-2019, 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 */
25extern char *pg_strdup(const char *in);
26extern void *pg_malloc(size_t size);
27extern void *pg_malloc0(size_t size);
28extern void *pg_malloc_extended(size_t size, int flags);
29extern void *pg_realloc(void *pointer, size_t size);
30extern void pg_free(void *pointer);
31
32/* Equivalent functions, deliberately named the same as backend functions */
33extern char *pstrdup(const char *in);
34extern void *palloc(Size size);
35extern void *palloc0(Size size);
36extern void *palloc_extended(Size size, int flags);
37extern void *repalloc(void *pointer, Size size);
38extern void pfree(void *pointer);
39
40/* sprintf into a palloc'd buffer --- these are in psprintf.c */
41extern char *psprintf(const char *fmt,...) pg_attribute_printf(1, 2);
42extern 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 */
45