Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
memnodes.h114 linesDownload Raw Back to nodes
1/*-------------------------------------------------------------------------2 *3 * memnodes.h4 *	  POSTGRES memory context node definitions.5 *6 *7 * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group8 * Portions Copyright (c) 1994, Regents of the University of California9 *10 * src/include/nodes/memnodes.h11 *12 *-------------------------------------------------------------------------13 */14#ifndef MEMNODES_H15#define MEMNODES_H16 17#include "nodes/nodes.h"18 19/*20 * MemoryContextCounters21 *		Summarization state for MemoryContextStats collection.22 *23 * The set of counters in this struct is biased towards AllocSet; if we ever24 * add any context types that are based on fundamentally different approaches,25 * we might need more or different counters here.  A possible API spec then26 * would be to print only nonzero counters, but for now we just summarize in27 * the format historically used by AllocSet.28 */29typedef struct MemoryContextCounters30{31	Size		nblocks;		/* Total number of malloc blocks */32	Size		freechunks;		/* Total number of free chunks */33	Size		totalspace;		/* Total bytes requested from malloc */34	Size		freespace;		/* The unused portion of totalspace */35} MemoryContextCounters;36 37/*38 * MemoryContext39 *		A logical context in which memory allocations occur.40 *41 * MemoryContext itself is an abstract type that can have multiple42 * implementations.43 * The function pointers in MemoryContextMethods define one specific44 * implementation of MemoryContext --- they are a virtual function table45 * in C++ terms.46 *47 * Node types that are actual implementations of memory contexts must48 * begin with the same fields as MemoryContextData.49 *50 * Note: for largely historical reasons, typedef MemoryContext is a pointer51 * to the context struct rather than the struct type itself.52 */53 54typedef void (*MemoryStatsPrintFunc) (MemoryContext context, void *passthru,55									  const char *stats_string,56									  bool print_to_stderr);57 58typedef struct MemoryContextMethods59{60	void	   *(*alloc) (MemoryContext context, Size size);61	/* call this free_p in case someone #define's free() */62	void		(*free_p) (void *pointer);63	void	   *(*realloc) (void *pointer, Size size);64	void		(*reset) (MemoryContext context);65	void		(*delete_context) (MemoryContext context);66	MemoryContext (*get_chunk_context) (void *pointer);67	Size		(*get_chunk_space) (void *pointer);68	bool		(*is_empty) (MemoryContext context);69	void		(*stats) (MemoryContext context,70						  MemoryStatsPrintFunc printfunc, void *passthru,71						  MemoryContextCounters *totals,72						  bool print_to_stderr);73#ifdef MEMORY_CONTEXT_CHECKING74	void		(*check) (MemoryContext context);75#endif76} MemoryContextMethods;77 78 79typedef struct MemoryContextData80{81	pg_node_attr(abstract)		/* there are no nodes of this type */82 83	NodeTag		type;			/* identifies exact kind of context */84	/* these two fields are placed here to minimize alignment wastage: */85	bool		isReset;		/* T = no space alloced since last reset */86	bool		allowInCritSection; /* allow palloc in critical section */87	Size		mem_allocated;	/* track memory allocated for this context */88	const MemoryContextMethods *methods;	/* virtual function table */89	MemoryContext parent;		/* NULL if no parent (toplevel context) */90	MemoryContext firstchild;	/* head of linked list of children */91	MemoryContext prevchild;	/* previous child of same parent */92	MemoryContext nextchild;	/* next child of same parent */93	const char *name;			/* context name (just for debugging) */94	const char *ident;			/* context ID if any (just for debugging) */95	MemoryContextCallback *reset_cbs;	/* list of reset/delete callbacks */96} MemoryContextData;97 98/* utils/palloc.h contains typedef struct MemoryContextData *MemoryContext */99 100 101/*102 * MemoryContextIsValid103 *		True iff memory context is valid.104 *105 * Add new context types to the set accepted by this macro.106 */107#define MemoryContextIsValid(context) \108	((context) != NULL && \109	 (IsA((context), AllocSetContext) || \110	  IsA((context), SlabContext) || \111	  IsA((context), GenerationContext)))112 113#endif							/* MEMNODES_H */114 
codekingpro/portable-devtools · Team Ai