[postgis-devel] [off-topic] Integrating C++ singletons into postgresql extensions???

Stephen Woodbridge woodbri at swoodbridge.com
Mon Oct 20 06:45:15 PDT 2014


On 10/20/2014 4:42 AM, Mateusz Łoskot wrote:
> FYI, Stephen has posted the same question to PostgreSQL ml, here
> http://www.postgresql.org/message-id/5441AD7A.3070809@swoodbridge.com
> where it received helpful and detailed answers

Mateusz,

Thank you for the follow up post on this. I had meant to do this but got 
side tracked. I'll be tackling this problem later this week so I'll try 
to follow up with more info on how it goes. strk's comment about 
_PG_init and _PG_fini was also very helpful.

-Steve

> M
>
> On 17 October 2014 20:32, Stephen Woodbridge <woodbri at swoodbridge.com> wrote:
>> Hi,
>>
>> I've been writing some new VRP solutions for pgRouting in C++ and I have a
>> few singleton classes like:
>>
>> 1. Config object that holds some general configuration information.
>> 2. Stats object for global stats collection.
>> 3. Logger object for enabling/disabling debug logging to a file.
>> 4. curlpp class for making outbound calls to OSRM from the c++ code
>>
>> I can probably do without 1-3 if I had to when the code is integrated, but
>> they are handy to keep around in the code for when we are developing and
>> working outside the postgresql database. And, would like to avoid cluttering
>> the code with tons of #ifdef.
>>
>> Item 4 is a little more problematic and needs to be kept around or something
>> else implemented to take its place.
>>
>> So my question(s) are:
>>
>> 1. Any insights into singletons working/not working within the postgresql
>> server extensions? My understanding is that these are implemented as global
>> static classes with a lifetime of the process and they have no destructor,
>> so I'm a little worried about memory leaks or multiple queries sharing the
>> singleton.
>>
>> 2. Is there another way of doing this for C++ code in the server?
>>
>> 3. What does PostGIS or GEOS do for logging?
>>
>> Any help or ideas would be appreciated.
>>
>> Thanks,
>>    -Steve
>> _______________________________________________
>> postgis-devel mailing list
>> postgis-devel at lists.osgeo.org
>> http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-devel
>
>
>




More information about the postgis-devel mailing list