Subject: C++ and Postgres

From: Walid Aref <[email-masked]>
Date: Thu, 14 Nov 91 18:52:48 -0800

I am using POSTGRES and gnu C++ running on a SPARC I station.
I am facing the following memory allocation problem:

I found somewhere in POSTGRES files
the following comment (actually when defining C functions for abstract data
types):

        /*
         * The Postgres memory  manager "palloc" must be used for all
         * space allocation. Do not  use "malloc".
         */

This is fine.
However, when using the class String (or possibly other C++ classes)
from the gnu C++ class library with POSTGRES, the class String internally
calls malloc/free/realloc. 
The whole system (postgres, my application, or both) crashes and memory gets 
corrupted. (segmentation fault, core dumped, etc.) when we make extensive use 
of strings interleaved with POSTGRES commands.
Did anyone face a similar problem  when using gnu C++ class library 
extensively intermixed with POSTGRES library calls?

Is this a real problem or are we doing something terribly wrong elsewhere?
or both :-)?

Thanks in advance.
walid

PS: The size of our executable code is around 4 Mega bytes. I am not sure
    if this is a useful piece of information, but just in case.

---

From: postarch (Postgres Mailing Archive)
Date: Fri, 15 Nov 91 21:35:31 PST

> Is this a real problem or are we doing something terribly wrong elsewhere?

I don't think this should be a problem for you.  The reason why we ask that
palloc be used is to prevent memory leaks.  It shouldn't cause any
complications in using malloc.  Some parts of the backend code use malloc, we
are just careful to explicitly free the allocated memory when we're done with
it.

An aside: In the front-end all palloc does is make a call to malloc, there's no 
difference.

Jeff Meredith
[email-masked]