[ale] OT: C not C++ Question

Chuck Huber chuck at cehuber.org
Mon Dec 30 12:22:30 EST 2002


On Mon, Dec 30, 2002 at 09:12:08AM -0500, cfowler wrote:
> On Mon, 2002-12-30 at 09:00, Chuck Huber wrote:
> >
> > 
> > Chris,  How much more work are you going to put into being lazy?
> > 
> > Enjoy,
> >     - Chuck
> 
> Funny.  I just hate rewriting code over and over and over again. I will
> tell you this.

Yeah, that was a really neat, and clean piece of code you sent.  When
I said "lazy", I was referring to memory management - not to the effort
of writing java-like C functions.  The java-like effort is obviously well
worth the time and would be a really good candidate to release to open source.
With inside knowledge of your project, you've probably already reused this
enough to more than justify its development.

I recall a post you made earlier regarding what to do with the memory
allocated as an argument to a function call.  If memory serves me correct
it went something like:

    while (...)
    {
        ...
        XXX_doSomething(YYY_new(...));
    }

and your concern was that you lost a reference to the YYY object and
were thus unable to destroy it.  Try this on for size:

    while (...)
    {
        YYY *tempyyy;

        ...
        tempyyy = YYY_new(...);
        XXX_doSomething(tempyyy);
        YYY_destroy(tempyyy);
    }

I know, it's more bulky than the java counterpart.

here's something to ponder...  I wonder if you could write something
like a blow_args function that took care of this for you:

    blow_args(XXX_doSomething, YYY_new(...), NULL);

It would then invoke the XXX_doSomething with the args that follow, then
call a destroy function on each arg.  It would be assumed that each of
the arguments is a java-like object, and thus has a pointer to it's
own destroy function.

Another option would be to take a look at the garbage collector
someone mentioned in a later post.  Now that sounds promising.

Enjoy,
    - Chuck

-- 
"The purpose of encryption is to protect good people
from bad people, not to protect bad people from the government."
     Scott McNealy, CEO Sun Microsystems
"The best way for government to control people is to remain in
   a constant threat of war." ---Karl Marx
(18 USC 242), which applies to government agents overstepping their
authority:
  "Whoever, under color of any law, statute, ordinance, regulation,
  or custom, willfully subjects any person in any State, Territory,
  or District to the deprivation of any rights, privileges, or
  immunities secured or protected by the Constitution or laws of
  the United States, . . . shall be fined under this title or
  imprisoned not more than one year, or both . . ."

 PGP signature




More information about the Ale mailing list