2021SC@SDUSC
SQLite 学习之路 第四节 cache具体结构
PgHdr1在pcache1.c里定义,PgHdr在pcache.c里定义,MemPage在btree.c里定义。PgHdr1的头是sqlite3_pcache_page的子类pghdr1包含需要查找的页面的页号信息;PgHdr保存了哪些页面是脏页;MemPage包含了数据库页的一些信息,可以理解为MemPage结构体。
sqlite3_pcache_page中的pBuf指向数据库页内容的开始地方,pExtra指向PgHdr
sqlite3_pcache_page结构体如下:
struct sqlite3_pcache_page {
void *pBuf; /* The content of the page */
void *pExtra; /* Extra information associated with the page */
};
新建一个page cache:
pPg = pcache1Alloc(pCache->szAlloc);
p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
p->page.pBuf = pPg;
p->page.pExtra = &p[1];
PCache 结构体如下: