Save a few bytes per CatCTup
От
cca5507
Тема
Save a few bytes per CatCTup
Дата
Msg-id
tencent_A42E0544C6184FE940CD8E3B14A3F0A39605@qq.com
Список
Дерево обсуждения
Save a few bytes per CatCTup "cca5507" <cca5507@qq.com>
Re: Save a few bytes per CatCTup Tom Lane <tgl@sss.pgh.pa.us>
Hi, The current code in CatalogCacheCreateEntry(): ``` ct = (CatCTup *) palloc(sizeof(CatCTup) + MAXIMUM_ALIGNOF + dtp->t_len); ct->tuple.t_len = dtp->t_len; ct->tuple.t_self = dtp->t_self; ct->tuple.t_tableOid = dtp->t_tableOid; ct->tuple.t_data = (HeapTupleHeader) MAXALIGN(((char *) ct) + sizeof(CatCTup)); /* copy tuple contents */ memcpy((char *) ct->tuple.t_data, (const char *) dtp->t_data, dtp->t_len); ``` If I understand correctly, we just want "ct->tuple.t_data" align to MAXIMUM_ALIGNOF here. So we can save MAXIMUM_ALIGNOF bytes per CatCTup by this: ``` ct = (CatCTup *) palloc(MAXALIGN(sizeof(CatCTup)) + dtp->t_len); ct->tuple.t_len = dtp->t_len; ct->tuple.t_self = dtp->t_self; ct->tuple.t_tableOid = dtp->t_tableOid; ct->tuple.t_data = (HeapTupleHeader) (((char *) ct) + MAXALIGN(sizeof(CatCTup))); /* copy tuple contents */ memcpy((char *) ct->tuple.t_data, (const char *) dtp->t_data, dtp->t_len); ``` It's correct because palloc() always return a max-aligned pointer. -- Regards, ChangAo Chen
В списке pgsql-hackers по дате отправления