Robert Haas escribió:
> On Mon, Feb 8, 2010 at 3:05 PM, Alvaro Herrera
> <alvherre@commandprompt.com> wrote:
> > How do we now that it works?
>
> Visual inspection? It's not very complicated.
Well, that works if you assume the trivial/usual malloc/free coding
style, but it fails in the hypothetical scenario I described earlier.
You could as well say that each rbtree must provide a memory context
that is going to be deleted when the tree is freed, instead of freeing
nodes one by one (and in fact it looks more efficient to do it that way
... except that we'd have to get in the business of strcpy'ing the
node's data). There's no way to know how this stuff is going to be
used, so if it's not going to be used now, I think we shouldn't
implement it. That's why I looked at the knngist patch too.
But hey, not that i care all that much either -- it's not a lot of code;
a couple dozen lines at most, and not complex.
> > (What, for example, if we were to allocate multiple nodes in a single
> > palloc chunk? I'm not familiar with this stuff but that seems
> > plausible)
>
> Well, then you could have the freefunc do something ((MyStruct *)
> a)->is_allocated = false.
Hmm, but isn't "a" gone at that point?
--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.