Re: Maintaining state across function calls

Поиск
Список
Период
Сортировка
От Craig Ringer
Тема Re: Maintaining state across function calls
Дата
Msg-id 50AADD2F.8080702@2ndQuadrant.com
обсуждение исходный текст
Ответ на Re: Maintaining state across function calls  (matt@byrney.com)
Ответы Re: Maintaining state across function calls  (Peter Geoghegan <peter@2ndquadrant.com>)
Re: Maintaining state across function calls  (Chris Angelico <rosuav@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: Vlad Marchenko
Дата:
Сообщение: Re: High SYS CPU - need advise
Следующее
От: Peter Geoghegan
Дата:
Сообщение: Re: Maintaining state across function calls