On Tue, Mar 10, 2026 at 8:59 PM Tender Wang <tndrwang@gmail.com> wrote:
>
> Hi,
>
> While learning how PostgreSQL implements streaming replication, I
> noticed that WalRcvShmemSize() calculating the shared
> memory sizes that use a multi-step add_size pattern for single,
> fixed-size structures.
> ...
> Size
> WalRcvShmemSize(void)
> {
> Size size = 0;
>
> size = add_size(size, sizeof(WalRcvData));
>
> return size;
> }
> ...
>
> "return sizeof(WalRcvData);" is equal to the above code.
> I searched the other modules to see how they perform the calculations.
> For example,
> ...
> Size
> VarsupShmemSize(void)
> {
> return sizeof(TransamVariablesData);
> }
> ...
> And I also found another case:
> Size
> XLogRecoveryShmemSize(void)
> {
> Size size;
>
> /* XLogRecoveryCtl */
> size = sizeof(XLogRecoveryCtlData);
>
> return size;
> }
>
> The above code does not need to define the local variable size;
> directly returning sizeof(XLogRecoveryCtlData) seems simpler.
I bet the compiler will optimize it away.
> I searched for other XXXShmemSize() calls in CalculateShmemSize() and
> simplified them where possible.
> Please see the attached patch.
>
> I realize this might be a matter of coding style preference rather
> than a functional necessity.
> Is it worth standardizing these cases, or should we stick with the
> current boilerplate for consistency?
> Any thoughts?
>
> --
> Thanks,
> Tender Wang
--
Regards
Junwang Zhao