gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
3.8KB

  1. /*-------------------------------------------------------------------------
  2. *
  3. * memnodes.h
  4. * POSTGRES memory context node definitions.
  5. *
  6. *
  7. * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
  8. * Portions Copyright (c) 1994, Regents of the University of California
  9. *
  10. * src/include/nodes/memnodes.h
  11. *
  12. *-------------------------------------------------------------------------
  13. */
  14. #ifndef MEMNODES_H
  15. #define MEMNODES_H
  16. #include "nodes/nodes.h"
  17. /*
  18. * MemoryContextCounters
  19. * Summarization state for MemoryContextStats collection.
  20. *
  21. * The set of counters in this struct is biased towards AllocSet; if we ever
  22. * add any context types that are based on fundamentally different approaches,
  23. * we might need more or different counters here. A possible API spec then
  24. * would be to print only nonzero counters, but for now we just summarize in
  25. * the format historically used by AllocSet.
  26. */
  27. typedef struct MemoryContextCounters
  28. {
  29. Size nblocks; /* Total number of malloc blocks */
  30. Size freechunks; /* Total number of free chunks */
  31. Size totalspace; /* Total bytes requested from malloc */
  32. Size freespace; /* The unused portion of totalspace */
  33. } MemoryContextCounters;
  34. /*
  35. * MemoryContext
  36. * A logical context in which memory allocations occur.
  37. *
  38. * MemoryContext itself is an abstract type that can have multiple
  39. * implementations.
  40. * The function pointers in MemoryContextMethods define one specific
  41. * implementation of MemoryContext --- they are a virtual function table
  42. * in C++ terms.
  43. *
  44. * Node types that are actual implementations of memory contexts must
  45. * begin with the same fields as MemoryContextData.
  46. *
  47. * Note: for largely historical reasons, typedef MemoryContext is a pointer
  48. * to the context struct rather than the struct type itself.
  49. */
  50. typedef void (*MemoryStatsPrintFunc) (MemoryContext context, void *passthru,
  51. const char *stats_string);
  52. typedef struct MemoryContextMethods
  53. {
  54. void *(*alloc) (MemoryContext context, Size size);
  55. /* call this free_p in case someone #define's free() */
  56. void (*free_p) (MemoryContext context, void *pointer);
  57. void *(*realloc) (MemoryContext context, void *pointer, Size size);
  58. void (*reset) (MemoryContext context);
  59. void (*delete_context) (MemoryContext context);
  60. Size (*get_chunk_space) (MemoryContext context, void *pointer);
  61. bool (*is_empty) (MemoryContext context);
  62. void (*stats) (MemoryContext context,
  63. MemoryStatsPrintFunc printfunc, void *passthru,
  64. MemoryContextCounters *totals);
  65. #ifdef MEMORY_CONTEXT_CHECKING
  66. void (*check) (MemoryContext context);
  67. #endif
  68. } MemoryContextMethods;
  69. typedef struct MemoryContextData
  70. {
  71. NodeTag type; /* identifies exact kind of context */
  72. /* these two fields are placed here to minimize alignment wastage: */
  73. bool isReset; /* T = no space alloced since last reset */
  74. bool allowInCritSection; /* allow palloc in critical section */
  75. const MemoryContextMethods *methods; /* virtual function table */
  76. MemoryContext parent; /* NULL if no parent (toplevel context) */
  77. MemoryContext firstchild; /* head of linked list of children */
  78. MemoryContext prevchild; /* previous child of same parent */
  79. MemoryContext nextchild; /* next child of same parent */
  80. const char *name; /* context name (just for debugging) */
  81. const char *ident; /* context ID if any (just for debugging) */
  82. MemoryContextCallback *reset_cbs; /* list of reset/delete callbacks */
  83. } MemoryContextData;
  84. /* utils/palloc.h contains typedef struct MemoryContextData *MemoryContext */
  85. /*
  86. * MemoryContextIsValid
  87. * True iff memory context is valid.
  88. *
  89. * Add new context types to the set accepted by this macro.
  90. */
  91. #define MemoryContextIsValid(context) \
  92. ((context) != NULL && \
  93. (IsA((context), AllocSetContext) || \
  94. IsA((context), SlabContext) || \
  95. IsA((context), GenerationContext)))
  96. #endif /* MEMNODES_H */
上海开阖软件有限公司 沪ICP备12045867号-1