Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes16kdownloads
memutils_internal.h137 linesDownload Raw Back to utils
1/*-------------------------------------------------------------------------2 *3 * memutils_internal.h4 *	  This file contains declarations for memory allocation utility5 *	  functions for internal use.6 *7 *8 * Portions Copyright (c) 2022-2023, PostgreSQL Global Development Group9 * Portions Copyright (c) 1994, Regents of the University of California10 *11 * src/include/utils/memutils_internal.h12 *13 *-------------------------------------------------------------------------14 */15 16#ifndef MEMUTILS_INTERNAL_H17#define MEMUTILS_INTERNAL_H18 19#include "utils/memutils.h"20 21/* These functions implement the MemoryContext API for AllocSet context. */22extern void *AllocSetAlloc(MemoryContext context, Size size);23extern void AllocSetFree(void *pointer);24extern void *AllocSetRealloc(void *pointer, Size size);25extern void AllocSetReset(MemoryContext context);26extern void AllocSetDelete(MemoryContext context);27extern MemoryContext AllocSetGetChunkContext(void *pointer);28extern Size AllocSetGetChunkSpace(void *pointer);29extern bool AllocSetIsEmpty(MemoryContext context);30extern void AllocSetStats(MemoryContext context,31						  MemoryStatsPrintFunc printfunc, void *passthru,32						  MemoryContextCounters *totals,33						  bool print_to_stderr);34#ifdef MEMORY_CONTEXT_CHECKING35extern void AllocSetCheck(MemoryContext context);36#endif37 38/* These functions implement the MemoryContext API for Generation context. */39extern void *GenerationAlloc(MemoryContext context, Size size);40extern void GenerationFree(void *pointer);41extern void *GenerationRealloc(void *pointer, Size size);42extern void GenerationReset(MemoryContext context);43extern void GenerationDelete(MemoryContext context);44extern MemoryContext GenerationGetChunkContext(void *pointer);45extern Size GenerationGetChunkSpace(void *pointer);46extern bool GenerationIsEmpty(MemoryContext context);47extern void GenerationStats(MemoryContext context,48							MemoryStatsPrintFunc printfunc, void *passthru,49							MemoryContextCounters *totals,50							bool print_to_stderr);51#ifdef MEMORY_CONTEXT_CHECKING52extern void GenerationCheck(MemoryContext context);53#endif54 55 56/* These functions implement the MemoryContext API for Slab context. */57extern void *SlabAlloc(MemoryContext context, Size size);58extern void SlabFree(void *pointer);59extern void *SlabRealloc(void *pointer, Size size);60extern void SlabReset(MemoryContext context);61extern void SlabDelete(MemoryContext context);62extern MemoryContext SlabGetChunkContext(void *pointer);63extern Size SlabGetChunkSpace(void *pointer);64extern bool SlabIsEmpty(MemoryContext context);65extern void SlabStats(MemoryContext context,66					  MemoryStatsPrintFunc printfunc, void *passthru,67					  MemoryContextCounters *totals,68					  bool print_to_stderr);69#ifdef MEMORY_CONTEXT_CHECKING70extern void SlabCheck(MemoryContext context);71#endif72 73/*74 * These functions support the implementation of palloc_aligned() and are not75 * part of a fully-fledged MemoryContext type.76 */77extern void AlignedAllocFree(void *pointer);78extern void *AlignedAllocRealloc(void *pointer, Size size);79extern MemoryContext AlignedAllocGetChunkContext(void *pointer);80extern Size AlignedAllocGetChunkSpace(void *pointer);81 82/*83 * How many extra bytes do we need to request in order to ensure that we can84 * align a pointer to 'alignto'.  Since palloc'd pointers are already aligned85 * to MAXIMUM_ALIGNOF we can subtract that amount.  We also need to make sure86 * there is enough space for the redirection MemoryChunk.87 */88#define PallocAlignedExtraBytes(alignto) \89	((alignto) + (sizeof(MemoryChunk) - MAXIMUM_ALIGNOF))90 91/*92 * MemoryContextMethodID93 *		A unique identifier for each MemoryContext implementation which94 *		indicates the index into the mcxt_methods[] array. See mcxt.c.95 *96 * For robust error detection, ensure that MemoryContextMethodID has a value97 * for each possible bit-pattern of MEMORY_CONTEXT_METHODID_MASK, and make98 * dummy entries for unused IDs in the mcxt_methods[] array.  We also try99 * to avoid using bit-patterns as valid IDs if they are likely to occur in100 * garbage data, or if they could falsely match on chunks that are really from101 * malloc not palloc.  (We can't tell that for most malloc implementations,102 * but it happens that glibc stores flag bits in the same place where we put103 * the MemoryContextMethodID, so the possible values are predictable for it.)104 */105typedef enum MemoryContextMethodID106{107	MCTX_UNUSED1_ID,			/* 000 occurs in never-used memory */108	MCTX_UNUSED2_ID,			/* glibc malloc'd chunks usually match 001 */109	MCTX_UNUSED3_ID,			/* glibc malloc'd chunks > 128kB match 010 */110	MCTX_ASET_ID,111	MCTX_GENERATION_ID,112	MCTX_SLAB_ID,113	MCTX_ALIGNED_REDIRECT_ID,114	MCTX_UNUSED4_ID				/* 111 occurs in wipe_mem'd memory */115} MemoryContextMethodID;116 117/*118 * The number of bits that 8-byte memory chunk headers can use to encode the119 * MemoryContextMethodID.120 */121#define MEMORY_CONTEXT_METHODID_BITS 3122#define MEMORY_CONTEXT_METHODID_MASK \123	((((uint64) 1) << MEMORY_CONTEXT_METHODID_BITS) - 1)124 125/*126 * This routine handles the context-type-independent part of memory127 * context creation.  It's intended to be called from context-type-128 * specific creation routines, and noplace else.129 */130extern void MemoryContextCreate(MemoryContext node,131								NodeTag tag,132								MemoryContextMethodID method_id,133								MemoryContext parent,134								const char *name);135 136#endif							/* MEMUTILS_INTERNAL_H */137 
codekingpro/portable-devtools · Team Ai