in reply to Why do closures save memory?

Why should closures be cheaper in this situation?

Its the difference between having one function and many. The closures can all use the same compiled code internally; only a copy of the lexical environment needs to be kept. Generating accessors by eval'ing them into existence, the strategy used by Class::Struct as revealed by PodMaster, results in newly compiled code for each one.

-sauoq
"My two cents aren't worth a dime.";

Replies are listed 'Best First'.
Re: Re: Why do closures save memory?
by bsb (Priest) on Jul 08, 2003 at 00:15 UTC
    Thanks. I thought that might be the reason but I didn't want to rig the ballot.

    I only started thinking about it after reading that note in Class::Accessor. Prior to that I'd naively assumed you got a whole new function even with closures.

    Brad