From 4cb621d24d8fe5004229f50524a9d5a518721e71 Mon Sep 17 00:00:00 2001 From: obarthel Date: Wed, 30 Mar 2022 09:33:25 +0200 Subject: [PATCH] Added documentation on side-effects caused by using MEMF_CLEAR --- library/amiga_pools.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/library/amiga_pools.c b/library/amiga_pools.c index b9c87ac..e72093c 100644 --- a/library/amiga_pools.c +++ b/library/amiga_pools.c @@ -67,7 +67,9 @@ struct MemoryPool * near the tail of the list. */ - ULONG mp_MemoryFlags; /* Memory attributes for allocation */ + ULONG mp_MemoryFlags; /* Memory attributes for allocation, + * which may also include MEMF_CLEAR. + */ ULONG mp_PuddleSize; /* Largest allocation which will fit * into a single puddle. */ @@ -282,6 +284,12 @@ static union PuddleUnion * create_new_puddle(struct MemoryPool * mp) * allocatable memory chunks within the memory header. * * Note: no overflow checking is performed! + * + * Also note that the original memory allocation flags are + * being used, which may include MEMF_CLEAR. This means that + * if MEMF_CLEAR is set, the initial allocation will be + * cleared and then the individual puddle allocations made + * through LibAllocPooled() will be cleared, too. */ pu = alloc_vec(sizeof(pu->pu_MemHeader) + puddle_size + sizeof(APTR), memory_flags); if (pu == NULL) @@ -388,6 +396,12 @@ APTR LibAllocPooled(APTR pool, ULONG mem_size) * the entire allocated memory which Allocate() * returned. It's been rounded up to be a * multiple of MEM_BLOCKSIZE. + * + * Note that the puddle will have been allocated + * with MEMF_CLEAR already, which does not render + * the following memset() call redundant, but + * making the initial puddle allocation use + * MEMF_CLEAR is definitely redundant. */ if ((mp->mp_MemoryFlags & MEMF_CLEAR) != 0) memset(result, 0, (mem_size + MEM_BLOCKMASK) & ~MEM_BLOCKMASK); @@ -464,7 +478,7 @@ VOID LibFreePooled(APTR pool, APTR memory, ULONG size) */ for (pu = (union PuddleUnion *)mp->mp_PuddleMinList.mlh_Head ; pu->pu_Node.ln_Succ != NULL ; - pu = (union PuddleUnion *)pu->pu_Node.ln_Succ) + pu = (union PuddleUnion *)pu->pu_Node.ln_Succ) { /* Did we reach the end of the puddle list? Then * the given memory address and/or size may be