Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
fe_memutils.h74 linesDownload Raw Back to common
1/*2 *	fe_memutils.h3 *		memory management support for frontend code4 *5 *	Copyright (c) 2003-2023, PostgreSQL Global Development Group6 *7 *	src/include/common/fe_memutils.h8 */9#ifndef FE_MEMUTILS_H10#define FE_MEMUTILS_H11 12/*13 * Flags for pg_malloc_extended and palloc_extended, deliberately named14 * the same as the backend flags.15 */16#define MCXT_ALLOC_HUGE			0x01	/* allow huge allocation (> 1 GB) not17										 * 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 failure23 * (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 *ptr, size_t size);30extern void pg_free(void *ptr);31 32/*33 * Variants with easier notation and more type safety34 */35 36/*37 * Allocate space for one object of type "type"38 */39#define pg_malloc_object(type) ((type *) pg_malloc(sizeof(type)))40#define pg_malloc0_object(type) ((type *) pg_malloc0(sizeof(type)))41 42/*43 * Allocate space for "count" objects of type "type"44 */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)))47 48/*49 * Change size of allocation pointed to by "pointer" to have space for "count"50 * objects of type "type"51 */52#define pg_realloc_array(pointer, type, count) ((type *) pg_realloc(pointer, sizeof(type) * (count)))53 54/* Equivalent functions, deliberately named the same as backend functions */55extern char *pstrdup(const char *in);56extern char *pnstrdup(const char *in, Size size);57extern void *palloc(Size size);58extern void *palloc0(Size size);59extern void *palloc_extended(Size size, int flags);60extern void *repalloc(void *pointer, Size size);61extern void pfree(void *pointer);62 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)))68 69/* sprintf into a palloc'd buffer --- these are in psprintf.c */70extern char *psprintf(const char *fmt,...) pg_attribute_printf(1, 2);71extern size_t pvsnprintf(char *buf, size_t len, const char *fmt, va_list args) pg_attribute_printf(3, 0);72 73#endif							/* FE_MEMUTILS_H */74 
codekingpro/portable-devtools · Team Ai