Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

What is a "stash"?

by John M. Dlugosz (Monsignor)
on Feb 05, 2003 at 21:14 UTC ( #232930=perlquestion: print w/replies, xml ) Need Help??
John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:

Toward the bottom of threads, it states, “When you return an object the entire stash that the object is blessed as well. This will lead to a large memory usage. The ideal situation would be to detect the original stash if it existed.”

What is a stash of an object, and what was he trying to say (I can‘t parse that first sentence)?

—John

Replies are listed 'Best First'.
Re: What is a "stash"? (%main::)
by tye (Sage) on Feb 06, 2003 at 02:33 UTC

    The quoted sentences do not make sense to me. But a "stash" is a symbol table, perhaps it is even short for "Symbol Table hASH". See Stashes and Globs in perlguts for more info.

                    - tye
Re: What is a "stash"?
by htoug (Deacon) on Feb 06, 2003 at 11:38 UTC
    A reasonable guess: "When you return an object the entire stash that the object is in is blessed as well"
    Googling a but led me to Change 18424 in the Perl source, where it is stated that it "Fixes bug #15273, the return of the object caused the stash of the object to be cloned, cloning the entire syntax tree and all lexicals in there creating danglning copies to the object. (Pararell but unlinked STASH tree). This adds a new flag, when set it will use STASHES from the thread we are joining into avoiding the problem."
    Not that this will explain it any further, but as far as I can understand, it means that when you return a variable from one thread to another, the the entire stash (read package) is made available to the other thread. Note this guess could be most amazingly and stupidly wrong so YMMV. It is obviously in the deep magic area. I think you have (at least) these options:
    • don your wizards hat and read the code
    • mail Arthur "Sky" Bergman and ask him
    • never mind and go on as before
    Henrik Tougaard: Not an internals wizard, but I have been in there and got out again nearly unscathed.
Re: What is a "stash"?
by Cabrion (Friar) on Feb 05, 2003 at 22:31 UTC
    The link in your question appears broken, so I am going at this without conext. However, I think the author was using "stash" so refer to whatever (scalar, array or hash) it was that was blessed. Objects don't have to be blessed hashes, that's just a convention. Largely due to the fact that 99% of the time a hash makes the most sense.
      Largely due to the fact that 99% of the time a hash makes the most sense.

      No. 99% of the time, the ease of using a hash instead of a module that will provide OO representation for you overrides the benefits of not using a hash.

      A hash is, in nearly every case, the least efficient way of representing an object. Much better is to use an array. (This, by the way, is why pseudo-hashes were created in 5.6 - the attempt to marry hashes and arrays.) Even better (from a space perspective) is to use one array for your entire class (if this is possible). But, you have to both have a baseclass that would represent this and the ability to hand this kind of book-keeping over to another module.

      ------
      We are the carpenters and bricklayers of the Information Age.

      Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

        I don't recall saying it was efficient. It just makes sense as you pointed out:

        the ease of using a hash instead of a module that will provide OO representation for you overrides the benefits of not using a hash so.... Yes, right?

        How one arrives at such a conclusion is not really important.

        I read that "all objects from an array" in one of O'Reilly's advanced perl books too. Having looked at the code required to maintain objects as arrays and the inability to play nicely with serialization tools like Data::Dumper was a real turn off.

        Besides, I think the post below referencing the "stash" is probably more correct that anything thus far.

        Warning: I am an expert in neither perl internals or perl threads - so this explanation may be wrong :-)

        I think that "stash" in this context is referring to the package symbol table (called a stash in the perl internals). Blessed references contain a pointer to the stash of the package they are blessed into.

        From the threads doc I am assuming that this is copied when an object is returned - when it would be more appropriate to use the the package's existing symbol table (if one exists).

Re: What is a "stash"?
by blahblah (Friar) on Feb 08, 2003 at 06:22 UTC
    The fact that no one finds the topic question an occasion for at least a little humour is very disappointing, because I can think of at least 10 funny "blessed stashes".

    :D

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://232930]
Approved by ChemBoy
Front-paged by htoug
help
Chatterbox?
and the daffodils sway...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2017-10-19 07:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (252 votes). Check out past polls.

    Notices?