1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2024-12-14 10:13:05 +02:00

Rearrange MemContext struct members to save space on 64-bit.

On 64-bit systems this saves a bit of space (10%) due to alignment. 32-bit systems see no benefit.

Also add tests for the individual struct sizes.
This commit is contained in:
David Steele 2021-08-19 11:12:56 -04:00
parent bab7a01f99
commit 9b45df7057
2 changed files with 14 additions and 4 deletions

View File

@ -50,11 +50,11 @@ Contains information about the memory context
***********************************************************************************************************************************/
struct MemContext
{
MemContextState state; // Current state of the context
const char *name; // Indicates what the context is being used for
MemContextState state; // Current state of the context
MemContext *contextParent; // All contexts have a parent except top
unsigned int contextParentIdx; // Index in the parent context list
MemContext *contextParent; // All contexts have a parent except top
MemContext **contextChildList; // List of contexts created in this context
unsigned int contextChildListSize; // Size of child context list (not the actual count of contexts)

View File

@ -74,6 +74,11 @@ testRun(void)
// *****************************************************************************************************************************
if (testBegin("memContextNew() and memContextFree()"))
{
TEST_TITLE("struct size");
TEST_RESULT_UINT(sizeof(MemContext), TEST_64BIT() ? 72 : 48, "MemContext size");
// -------------------------------------------------------------------------------------------------------------------------
// Make sure top context was created
TEST_RESULT_Z(memContextName(memContextTop()), "TOP", "top context should exist");
TEST_RESULT_INT(memContextTop()->contextChildListSize, 0, "top context should init with zero children");
@ -146,7 +151,7 @@ testRun(void)
"context child list initial size");
// This test will change if the contexts above change
TEST_RESULT_UINT(memContextSize(memContextTop()), TEST_64BIT() ? 960 : 544, "check size");
TEST_RESULT_UINT(memContextSize(memContextTop()), TEST_64BIT() ? 896 : 544, "check size");
TEST_ERROR(
memContextFree(memContextTop()->contextChildList[MEM_CONTEXT_INITIAL_SIZE]),
@ -169,6 +174,11 @@ testRun(void)
// *****************************************************************************************************************************
if (testBegin("memContextAlloc(), memNew*(), memGrow(), and memFree()"))
{
TEST_TITLE("struct size");
TEST_RESULT_UINT(sizeof(MemContextAlloc), 8, "MemContextAlloc size");
// -------------------------------------------------------------------------------------------------------------------------
TEST_RESULT_UINT(sizeof(MemContextAlloc), 8, "check MemContextAlloc size (same for 32/64 bit)");
TEST_RESULT_PTR(MEM_CONTEXT_ALLOC_BUFFER((void *)1), (void *)(sizeof(MemContextAlloc) + 1), "check buffer macro");
TEST_RESULT_PTR(MEM_CONTEXT_ALLOC_HEADER((void *)sizeof(MemContextAlloc)), (void *)0, "check header macro");
@ -223,7 +233,7 @@ testRun(void)
TEST_RESULT_UINT(memContextCurrent()->allocFreeIdx, MEM_CONTEXT_ALLOC_INITIAL_SIZE + 3, "check alloc free idx");
// This test will change if the allocations above change
TEST_RESULT_UINT(memContextSize(memContextCurrent()), TEST_64BIT() ? 249 : 165, "check size");
TEST_RESULT_UINT(memContextSize(memContextCurrent()), TEST_64BIT() ? 241 : 165, "check size");
TEST_ERROR(
memFree(NULL), AssertError,