Skip site navigation (1) Skip section navigation (2)

Re: inline newNode()

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Neil Conway <neilc(at)samurai(dot)com>,PostgreSQL Patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: inline newNode()
Date: 2002-10-09 00:07:30
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackerspgsql-patches
Peter Eisentraut wrote:
> Tom Lane writes:
> > A brute-force approach is to say "we know _start is word-aligned because
> > we just got it from palloc, which guarantees MAXALIGNment".  We could
> > make a variant version of MemSet that omits the alignment check, and use
> > it here and anywhere else we're sure it's safe.
> Or make a version of palloc that zeroes the memory.

OK, here is a version of newNode that is a macro.  However, there are

First, I can't get the code to assign the tag (dereference the pointer)
_and_ return the pointer, in a macro.  I can convert it to take a third
pointer argument, and it is only called <10 times, so that is easy, but
it is used by makeNode, which is called ~1000 times, so that seems like
a bad idea.  My solution was to declare a global variable in the header
file to be used by the macro.  Because the macro isn't called
recursively, that should be fine.

Now, the other problem is MemSet.  MemSet isn't designed to be called
inside a macro.  In fact, the 'if' tests are easy to do in a macro with
"? :", but the "while" loop seems to be impossible in a macro.  I tried
seeing if 'goto' would work in a macro, but of course it doesn't, and
even if it did, I doubt it would be portable.  The patch merely calls
memset() rather than MemSet.

Not sure if this is a win or not.  It makes makeNode a macro, but
removes the use of the MemSet macro in favor of memset().

Does anyone have additional suggestions?  The only thing I can suggest
is to make a clear-memory version of palloc because palloc always calls
MemoryContextAlloc() so I can put it in there.  How does that sound? 

However, now that I look at it, MemoryContextAlloc() could be made a
macro easier than newNode() and that would save function call in more
cases than newNode.  In fact, the comment at the top of
MemoryContextAlloc() says:

 * This could be turned into a macro, but we'd have to import
 * nodes/memnodes.h into postgres.h which seems a bad idea.


The regression tests do pass with this patch, so functionally it works

  Bruce Momjian                        |
  pgman(at)candle(dot)pha(dot)pa(dot)us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

In response to


pgsql-hackers by date

Next:From: Bruce MomjianDate: 2002-10-09 00:26:57
Subject: Re: [HACKERS] Hot Backup
Previous:From: Josh BerkusDate: 2002-10-08 23:36:40
Subject: Re: CHAR, VARCHAR, TEXT (Was Large Databases)

pgsql-patches by date

Next:From: Tom LaneDate: 2002-10-09 04:12:12
Subject: Re: inline newNode()
Previous:From: Neil ConwayDate: 2002-10-08 22:59:44
Subject: Re: inline newNode()

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group