|From:||Aaron Patterson <tenderlove(at)ruby-lang(dot)org>|
|Subject:||Custom allocators in libpq|
|Views:||Raw Message | Whole Thread | Download mbox | Resend email|
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
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
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
|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|