Re: Retrieve memory size allocated by libpq - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Retrieve memory size allocated by libpq
Date
Msg-id 19922.1536706795@sss.pgh.pa.us
Whole thread Raw
In response to Re: Retrieve memory size allocated by libpq  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: Retrieve memory size allocated by libpq  (Pavel Stehule <pavel.stehule@gmail.com>)
List pgsql-hackers
Pavel Stehule <pavel.stehule@gmail.com> writes:
> The implementation of PQresultMemsize is simple and correct.

Hm, well, only for small values of "correct".  A quick look at PQclear
to see just what it clears shows that PGEvent objects associated with the
PGresult were overlooked.  While that's not hard to fix (and I did so),
there's a problem hiding behind that: we have no idea what sort of
"instance data" the external event procedures may have associated with
the PGresult.  In principle, any space occupied by such data needs to
be accounted for in this number.

This isn't an issue if the event procedure takes the lazy man's approach
of using PQresultAlloc to allocate such data.  That's recommendable anyway
since it saves having to write cleanup logic; and even if you don't do it
like that, the space involved may be negligible.  Still, I can foresee an
eventual need to let event procedures adjust the result-size number,
along the lines of PQincrementMemorySize(PGresult *res, size_t delta).
But that can probably wait till somebody actually requests it.

I didn't like the name "PQresultMemsize" much either, and changed it to
"PQresultMemorySize", which seems more in keeping with naming and
capitalization conventions elsewhere in libpq.

Pushed with those and some cosmetic changes.

            regards, tom lane


pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: libpq stricter integer parsing
Next
From: Thomas Munro
Date:
Subject: Re: [HACKERS] Can ICU be used for a database's default sort order?