Re: Maintaining state across function calls - Mailing list pgsql-general

From Craig Ringer
Subject Re: Maintaining state across function calls
Date
Msg-id 50AADD2F.8080702@2ndQuadrant.com
Whole thread Raw
In response to Re: Maintaining state across function calls  (matt@byrney.com)
Responses Re: Maintaining state across function calls  (Peter Geoghegan <peter@2ndquadrant.com>)
Re: Maintaining state across function calls  (Chris Angelico <rosuav@gmail.com>)
List pgsql-general
On 11/19/2012 10:09 PM, matt@byrney.com wrote:
> Thanks for your reply.  A follow-up question: to use the palloc/pfree
> functions with a C++ STL container, do I simply give the container an
> allocator which uses palloc and pfree instead of the default allocator,
> which uses new and delete?
If at all possible, isolate your C++ code from the PostgreSQL aggregate
implementation. Pass the C++ code pre-allocated buffers to work with if
you can, and manage the allocations in the Pg C code. Turn your C++ code
into library that presents only `extern "C"` interfaces and opaque types
if yu can.

C++ exception handling and the PostgreSQL backend's longjmp() based
error handling will interact in exciting and interesting ways. Avoid
calling `palloc`, `pfree` etc from within C++ if you can. If you really
must, ensure that your C++ code doesn't use any RAII, stack-allocated
objects with dtors, etc.

Otherwise you'll have to translate error handling mechanisms at every
boundary between C++ and Pg code, something I'm not even certain is
possible to do reliably.

--
 Craig Ringer                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services



pgsql-general by date:

Previous
From: Vlad Marchenko
Date:
Subject: Re: High SYS CPU - need advise
Next
From: Peter Geoghegan
Date:
Subject: Re: Maintaining state across function calls