日期:2014-05-16  浏览次数:20386 次

pg的内存管理机制三:AllocSet/MemoryContext实例删除和内存回收

?

话说 MemoryContextMethods 结构里的函数实现了pgAllocSet/MemoryContext 的内存管理机制,定义见下面。

typedef struct MemoryContextMethods

{

???? void ?? *(*alloc) (MemoryContext context, Size size);

???? /* call this free_p in case someone #define's free() */

???? void ???? (* free_p ) (MemoryContext context, void *pointer);

???? void ?? *(*realloc) (MemoryContext context, void *pointer, Size size);

???? void ???? (*init) (MemoryContext context);

???? void ???? (*reset) (MemoryContext context);

???? void ???? (*delete ) (MemoryContext context);

???? Size???? (*get_chunk_space) (MemoryContext context, void *pointer);

???? bool ???? (*is_empty) (MemoryContext context);

???? void ???? (*stats) (MemoryContext context);

#ifdef MEMORY_CONTEXT_CHECKING

???? void ???? (*check) (MemoryContext context);

#endif

} MemoryContextMethods;

?

其中deleteAllocSet 的静态函数 AllocSetDelete () 实现,具体签名在下面。它实现了AllocSet 相关的内存删除机制。而Mem