fe_memutils.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * fe_memutils.h
  3. * memory management support for frontend code
  4. *
  5. * Copyright (c) 2003-2016, 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. * Flags for pg_malloc_extended and palloc_extended, deliberately named
  13. * the same as the backend flags.
  14. */
  15. #define MCXT_ALLOC_HUGE 0x01 /* allow huge allocation (> 1 GB) not
  16. * actually used for frontends */
  17. #define MCXT_ALLOC_NO_OOM 0x02 /* no failure if out-of-memory */
  18. #define MCXT_ALLOC_ZERO 0x04 /* zero allocated memory */
  19. /*
  20. * "Safe" memory allocation functions --- these exit(1) on failure
  21. * (except pg_malloc_extended with MCXT_ALLOC_NO_OOM)
  22. */
  23. extern char *pg_strdup(const char *in);
  24. extern void *pg_malloc(size_t size);
  25. extern void *pg_malloc0(size_t size);
  26. extern void *pg_malloc_extended(size_t size, int flags);
  27. extern void *pg_realloc(void *pointer, size_t size);
  28. extern void pg_free(void *pointer);
  29. /* Equivalent functions, deliberately named the same as backend functions */
  30. extern char *pstrdup(const char *in);
  31. extern void *palloc(Size size);
  32. extern void *palloc0(Size size);
  33. extern void *palloc_extended(Size size, int flags);
  34. extern void *repalloc(void *pointer, Size size);
  35. extern void pfree(void *pointer);
  36. /* sprintf into a palloc'd buffer --- these are in psprintf.c */
  37. extern char *psprintf(const char *fmt,...) pg_attribute_printf(1, 2);
  38. extern size_t pvsnprintf(char *buf, size_t len, const char *fmt, va_list args) pg_attribute_printf(3, 0);
  39. #endif /* FE_MEMUTILS_H */