doc PG 17 relnotes: add FETCH_COUNT item
[pgsql.git] / src / include / common / fe_memutils.h
blob492cc97e8d19accf85a68916f75abe0b2e08f9ae
1 /*
2 * fe_memutils.h
3 * memory management support for frontend code
5 * Copyright (c) 2003-2024, PostgreSQL Global Development Group
7 * src/include/common/fe_memutils.h
8 */
9 #ifndef FE_MEMUTILS_H
10 #define FE_MEMUTILS_H
13 * Flags for pg_malloc_extended and palloc_extended, deliberately named
14 * the same as the backend flags.
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 */
22 * "Safe" memory allocation functions --- these exit(1) on failure
23 * (except pg_malloc_extended with MCXT_ALLOC_NO_OOM)
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 *ptr, size_t size);
30 extern void pg_free(void *ptr);
33 * Variants with easier notation and more type safety
37 * Allocate space for one object of type "type"
39 #define pg_malloc_object(type) ((type *) pg_malloc(sizeof(type)))
40 #define pg_malloc0_object(type) ((type *) pg_malloc0(sizeof(type)))
43 * Allocate space for "count" objects of type "type"
45 #define pg_malloc_array(type, count) ((type *) pg_malloc(sizeof(type) * (count)))
46 #define pg_malloc0_array(type, count) ((type *) pg_malloc0(sizeof(type) * (count)))
49 * Change size of allocation pointed to by "pointer" to have space for "count"
50 * objects of type "type"
52 #define pg_realloc_array(pointer, type, count) ((type *) pg_realloc(pointer, sizeof(type) * (count)))
54 /* Equivalent functions, deliberately named the same as backend functions */
55 extern char *pstrdup(const char *in);
56 extern char *pnstrdup(const char *in, Size size);
57 extern void *palloc(Size size);
58 extern void *palloc0(Size size);
59 extern void *palloc_extended(Size size, int flags);
60 extern void *repalloc(void *pointer, Size size);
61 extern void pfree(void *pointer);
63 #define palloc_object(type) ((type *) palloc(sizeof(type)))
64 #define palloc0_object(type) ((type *) palloc0(sizeof(type)))
65 #define palloc_array(type, count) ((type *) palloc(sizeof(type) * (count)))
66 #define palloc0_array(type, count) ((type *) palloc0(sizeof(type) * (count)))
67 #define repalloc_array(pointer, type, count) ((type *) repalloc(pointer, sizeof(type) * (count)))
69 /* sprintf into a palloc'd buffer --- these are in psprintf.c */
70 extern char *psprintf(const char *fmt,...) pg_attribute_printf(1, 2);
71 extern size_t pvsnprintf(char *buf, size_t len, const char *fmt, va_list args) pg_attribute_printf(3, 0);
73 #endif /* FE_MEMUTILS_H */