1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-31 22:04:40 +03:00

Add PQresultMemorySize function to report allocated size of a PGresult.

This number can be useful for application memory management, and the
overhead to track it seems pretty trivial.

Lars Kanis, reviewed by Pavel Stehule, some mods by me

Discussion: https://postgr.es/m/fa16a288-9685-14f2-97c8-b8ac84365a4f@greiz-reinsdorf.de
This commit is contained in:
Tom Lane
2018-09-11 18:45:02 -04:00
parent e7a2217978
commit 2970afa6cf
5 changed files with 70 additions and 6 deletions

View File

@ -6387,6 +6387,32 @@ void *PQresultAlloc(PGresult *res, size_t nBytes);
</listitem>
</varlistentry>
<varlistentry id="libpq-pqresultmemorysize">
<term>
<function>PQresultMemorySize</function>
<indexterm>
<primary>PQresultMemorySize</primary>
</indexterm>
</term>
<listitem>
<para>
Retrieves the number of bytes allocated for
a <structname>PGresult</structname> object.
<synopsis>
size_t PQresultMemorySize(const PGresult *res);
</synopsis>
</para>
<para>
This value is the sum of all <function>malloc</function> requests
associated with the <structname>PGresult</structname> object, that is,
all the space that will be freed by <function>PQclear</function>.
This information can be useful for managing memory consumption.
</para>
</listitem>
</varlistentry>
<varlistentry id="libpq-pqlibversion">
<term>
<function>PQlibVersion</function>
@ -6960,6 +6986,14 @@ void *PQinstanceData(const PGconn *conn, PGEventProc proc);
int PQresultSetInstanceData(PGresult *res, PGEventProc proc, void *data);
</synopsis>
</para>
<para>
Beware that any storage represented by <parameter>data</parameter>
will not be accounted for by <function>PQresultMemorySize</function>,
unless it is allocated using <function>PQresultAlloc</function>.
(Doing so is recommendable because it eliminates the need to free
such storage explicitly when the result is destroyed.)
</para>
</listitem>
</varlistentry>