Re: commit -- fixed UT_RBTree erase method


Subject: Re: commit -- fixed UT_RBTree erase method
From: Joaquin Cuenca Abela (e98cuenc@yahoo.com)
Date: Fri Jul 20 2001 - 10:15:46 CDT


--- Mike Nordell <tamlin@algonet.se> wrote:
> Joaquin Cuenca Abela wrote:
> >

> > P.S.: Anybody knows if we can safely suppose that
> our
> > supported compilers do the right thing in presence
> of
> > an inlined function that declares a static
> variable?
>
> Assuming s/declare/define/, and what you had in mind
> was something like:
>
> #include <stdio.h>
> inline void foo() { static int i=0; printf("%d\n",
> ++i); }
> void t1() { foo(); }
> void t2() { foo(); }
> int main() { t1(); t2(); return 0; }
>
> then, even that the code gerenared (printf...) gets
> inlined into t1 and t2,
> MSVC outputs
> 1
> 2
>
> i.e. it treats it as the one and same static
> variable. I'd strongly
> recomment against such constructions. What problem
> are you trying to solve?

The problem is this one:

I need leaf UT_RBTree::Node's. There are always
black, and we don't care about their values for left,
right, or parent[*] members.

If I add a new UT_RBTree::Node per leaf, the memory
consumation will grow by a factor of 2x. So instead I
use the same node for all the leaf's. This one can be
shared by various instances of trees, so one
possibility is to use a static variable in UT_RBTree
to store this "leaf".

The problem is that forgives the use of UT_RBTree by
code that it's executed before main(), so I've put
this variable into a method (getLeaf()), that returns
a static (local to the method) Node.

This method being 2 simple lines very used I wanted to
inline it, but the second time that inline was defined
by the commitee, their behaviour in this case was to
create various static variables, which is not the
intended behaviour. Third definition of inline fixed
this problem, and this one is the definition that got
into the standard (the was that msvc implements it).

And that it's my problem. The question was motivated
mainly by curiosity (I store the leaf in a local
pointer in each method, so now I only do one call to
getLeaf() per operation. I don't think that the
performance impact would be very high even if I call
each time getLeaf()).

Now I'm curious to know what are the main concerns
about the utilisation of inline methods with static
variables (besides the portability ones and the MT
ones). (When I look at your example, I see that it
may become very messy, giving the impression that
we're sharing the same static variable by two
different methods, but that's not really different
from using a non-inlined method).

Looking forward for your alternatives

Cheers,

--
Joaquín Cuenca Abela
e98cuenc@yahoo.com

__________________________________________________ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/



This archive was generated by hypermail 2b25 : Fri Jul 20 2001 - 10:15:48 CDT