1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-08 11:42:09 +03:00

Provide a way to supress the "out of memory" error when allocating.

Using the new interface MemoryContextAllocExtended, callers can
specify MCXT_ALLOC_NO_OOM if they are prepared to handle a NULL
return value.

Michael Paquier, reviewed and somewhat revised by me.
This commit is contained in:
Robert Haas
2015-01-30 12:56:48 -05:00
parent 3d660d33aa
commit bd4e2fd97d
2 changed files with 49 additions and 0 deletions

View File

@ -42,12 +42,21 @@ typedef struct MemoryContextData *MemoryContext;
*/
extern PGDLLIMPORT MemoryContext CurrentMemoryContext;
/*
* Flags for MemoryContextAllocExtended.
*/
#define MCXT_ALLOC_HUGE 0x01 /* allow huge allocation (> 1 GB) */
#define MCXT_ALLOC_NO_OOM 0x02 /* no failure if out-of-memory */
#define MCXT_ALLOC_ZERO 0x04 /* zero allocated memory */
/*
* Fundamental memory-allocation operations (more are in utils/memutils.h)
*/
extern void *MemoryContextAlloc(MemoryContext context, Size size);
extern void *MemoryContextAllocZero(MemoryContext context, Size size);
extern void *MemoryContextAllocZeroAligned(MemoryContext context, Size size);
extern void *MemoryContextAllocExtended(MemoryContext context,
Size size, int flags);
extern void *palloc(Size size);
extern void *palloc0(Size size);