Re: Memory Management in pqlib, Garbage Collection support

Поиск
Список
Период
Сортировка
От Alexander Reichstadt
Тема Re: Memory Management in pqlib, Garbage Collection support
Дата
Msg-id E2750389-4828-434D-9584-6F9EF2A9B5F8@mac.com
обсуждение исходный текст
Ответ на Re: Memory Management in pqlib, Garbage Collection support  (Simon Riggs <simon@2ndQuadrant.com>)
Список pgsql-general
(Sorry, I meant libpq). Actually it's finalize in Objective-C as well. PGSQLKit is the ObjC wrapper framework for
libpq.I was confused by what I had learnt about GC, being it can't mix with non-GC. What the docu didn't mention in the
placesI read --or at least not so that it stuck-- was that it does link against C-libs regardless of GC and without
throwingany kind of warning or error.  

So, if I understand this correctly, if I want to use GC in my frontend app, which links against PGSQLKit which links
againstlibpq, I need to enhance PGSQLKit to support GC by adding finalizers for management of libpq's memory use to
makeGC available in all projects wanting to link against PGSQLKit, yes? 



Am 03.05.2012 um 10:32 schrieb Simon Riggs:
Am 03.05.2012 um 10:13 schrieb Peter Bex:
>
> OK, so you're specifically talking about Objective C.  I don't know much
> about that language, but unless there are specific ObjC-bindings for
> libpq (like libpq++ for C++), you'll need to perform manual memory
> management and call PQClear yourself.
>
>> As GC is an evolutionary stage across languages [...]
>
> […]

> I think if you want something similar you'll either need to write your
> own ObjC class to wrap the C functions or look for something pre-existing.
> Perhaps you can use libpq++.  I've also found a "PostgreSQL Cocoa Framework"
> project (but it appears to be abandoned): http://pgsqlcocoa.sourceforge.net/
Thanks for the pointer, but it's distributed under GPL, I can't use that. PGSQLKit is like PG, a BSD-style license.
That'swhat brought me from MySQL to PG. 

>
>> In general there are libs that provide garbage collection for C as well, like here:
>> <http://www.hpl.hp.com/personal/Hans_Boehm/gc/>
>
> The Boehm GC is a good prototyping solution but not very suitable for
> general use.  It's an especially bad idea to force use of such a garbage
> collector on the user whenever using libpq.  This would also prohibit
> the integration of libpq with other languages and their GCs.

I didn't look inside, I really just looked up Wikipedia on the subject and if there are ways to get GC into C somehow
andseemed to have gotten lucky. 

> AFAIK libpq currently does not offer specifying callback functions to
> use for allocating and freeing objects (it uses malloc/free directly).
> If this was available, it would be even easier to integrate deeply with
> a custom GC.
>
>> For example, it'd help avoid leaks like those caused by a result not being PQclear'ed.
>
> C programmers are generally comfortable with manual memory management, or
> they'd use another language.

It's ok, I like Cocoa's GC though.


В списке pgsql-general по дате отправления:

Предыдущее
От: Alban Hertroys
Дата:
Сообщение: Re: Memory Management in pqlib, Garbage Collection support
Следующее
От: Chrishelring
Дата:
Сообщение: Re: Uppercase to lowercase trigger?