Thread: Question regarding the internal memory management

Question regarding the internal memory management

From
"Biker Conrad"
Date:
Hi, there:

I am new to postgreSQL and I was wondering where I can find more information
regarding the memory allocation and deallocation process in postgreSQL.
Basically, I read the parser yacc grammar (src/backend/parser/gram.y) and I
couldn't figure out when does the program deallocate the nodes created
during the parsing process (using the makeNode macro) in case there are
parsing errors. If didn't have time to dig more and I thought maybe someone
can answer my question or can direct me to some documentation about this
topic.

Thank you





Re: Question regarding the internal memory management

From
Holger Krug
Date:
On Fri, Jan 18, 2002 at 12:09:38AM -0800, Biker Conrad wrote:
> I am new to postgreSQL and I was wondering where I can find more information
> regarding the memory allocation and deallocation process in postgreSQL.
> Basically, I read the parser yacc grammar (src/backend/parser/gram.y) and I
> couldn't figure out when does the program deallocate the nodes created
> during the parsing process (using the makeNode macro) in case there are
> parsing errors. If didn't have time to dig more and I thought maybe someone
> can answer my question or can direct me to some documentation about this
> topic.

`makeNode' calls `newNode' and newNode call `palloc'.
`palloc' performs the memory allocation in `CurrentMemoryContext',
which is `QueryContext' for parsing.

Concerning `QueryContext' I'll cite from the code (postgres.c):

     * QueryContext is reset once per iteration of the main loop, ie, upon
     * completion of processing of each supplied query string. It can
     * therefore be used for any data that should live just as long as the
     * query string --- parse trees, for example.

src/backend/utils/mmgr/README informs you about how memory management is done
in PostgreSQL.

--
Holger Krug
hkrug@rationalizer.com