From: | Aaron Patterson <tenderlove(at)ruby-lang(dot)org> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Custom allocators in libpq |
Date: | 2017-08-28 17:28:34 |
Message-ID: | 20170828172834.GA71455@TC.local |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hello!
I would like to be able to configure libpq with custom malloc functions.
The reason is that we have a Ruby wrapper that exposes libpq in Ruby.
The problem is that Ruby's GC doesn't know how much memory has been
allocated by libpq, so no pressure is applied to the GC when it should
be. Ruby exports malloc functions that automatically apply GC pressure,
and I'd like to be able to configure libpq to use those malloc
functions.
I've attached two patches that add this functionality. The first patch
introduces a new function `PQunescapeByteaConn` which takes a
connection (so we have a place to get the malloc functions). We already
have `PQescapeBytea` and `PQescapeByteaConn`, this first patch gives us
the analogous `PQunescapeBytea` and `PQunescapeByteaConn`.
The second patch adds malloc function pointer fields to `PGEvent`,
`pg_result`, and `pg_conn` structs, and changes libpq internals to use
those allocators rather than directly calling `malloc`.
This patch doesn't replace all malloc calls to the configured ones, just
the mallocs related to creating result objects (which is what I'm
concerned with).
If there's something I'm missing, please let me know. This is my first
patch to libpq, so I look forward to hearing feedback. Thanks for your
time!
--
Aaron Patterson
http://tenderlovemaking.com/
Attachment | Content-Type | Size |
---|---|---|
0001-add-PQunescapeByteaConn-for-unescaping-bytes-given-a.patch | text/plain | 3.1 KB |
0002-use-configured-malloc-free-from-the-connection.patch | text/plain | 9.4 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Robert Haas | 2017-08-28 17:43:22 | Re: [BUGS] [postgresql 10 beta3] unrecognized node type: 90 |
Previous Message | Antonin Houska | 2017-08-28 16:23:23 | Write operations in parallel mode |