Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Hashes/Scalars and Memory Usage
by Fastolfe (Vicar) on Feb 09, 2001 at 00:12 UTC | |
The long answer: Any scalar variable is stored in an SV internally. A hash is just a container around a bunch of SV's. I don't know if either method will be necessarily "less efficient" (are you talking about memory or execution time?). On one hand you have the hash lookup to find the value you're looking for in a hash, and on the other hand you have a symbol table lookup for individual scalars (though I guess different variable scoping conventions could make that work differently -- someone else may be able to provide more information). I honestly don't think there's any serious gain one way or the other, and as a Perl developer you shouldn't have to worry about such a thing, especially with only 30 variables. Use what makes the most sense in your code, but avoid playing tricks with soft references that could come around and bite you in the ass later on. Hope this helps. | [reply] |
by EvilTypeGuy (Initiate) on Feb 09, 2001 at 01:06 UTC | |
I ended up settling with the above situation. Each field that's on the form (and these are very complex forms at times..) gets it's own little section like that for clarity. By placing it in the code block, the variable goes out of scope as soon as the block's done...(since I no longer need the variable...) Is this the Wrong Thing to Do(TM)? | [reply] [d/l] |
by Fastolfe (Vicar) on Feb 09, 2001 at 02:44 UTC | |
If your code varies in more than this respect (e.g. size, the use of another hash key besides CompanyInfo, etc), you could re-structure the @FIELDS array something like this: Then adapt your code to follow suit.. | [reply] [d/l] [select] |
by EvilTypeGuy (Initiate) on Feb 10, 2001 at 02:14 UTC | |
by EvilTypeGuy (Initiate) on Feb 09, 2001 at 01:01 UTC | |
| [reply] |
by EvilTypeGuy (Initiate) on Feb 13, 2001 at 03:59 UTC | |
So now in my 'tabs', (this is through a web browser don't ask how :p) I can neat things like: (in the app i'm working on each subroutine is a different tab, and there's a complex management system that works completely behind the scenes to manage the user's navigation through the tabs)... This works great for me, before I had two screens that totaled 415 lines, after this, both screens plus the display routine totaled 123 lines :) Mmmmm, Diet Code(TM)... Thanks Fastolfe! | [reply] [d/l] [select] |
|
Re: Hashes/Scalars and Memory Usage
by InfiniteSilence (Curate) on Feb 09, 2001 at 00:32 UTC | |
Celebrate Intellectual Diversity | [reply] [d/l] |
by Fastolfe (Vicar) on Feb 09, 2001 at 00:52 UTC | |
| [reply] [d/l] |
|
Re: Hashes/Scalars and Memory Usage
by kschwab (Vicar) on Feb 09, 2001 at 00:19 UTC | |
They seem to be identical in memory usage.
Process 1: Text VSS: 1.9mb Data VSS: 8.1mb Stack VSS: 16kb Shmem VSS: 0kb Other VSS: 0kb Total VSS: 10mb Process 2: Text VSS: 1.9mb Data VSS: 8.1mb Stack VSS: 16kb Shmem VSS: 0kb Other VSS: 0kb Total VSS: 10mb I would suspect how you end up populating/using the scalars and/or hashes would have a greater effect. | [reply] [d/l] |
|
Re: Hashes/Scalars and Memory Usage
by AgentM (Curate) on Feb 09, 2001 at 00:28 UTC | |
AgentM was just blowing gas here. Never mind.
Thanks to Fastolfe, chipmunk, myocom for the explanations and for catching my mistake.
AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR. | [reply] |
by Fastolfe (Vicar) on Feb 09, 2001 at 00:32 UTC | |
The string in the array assignment is being interpreted in a numeric context, which makes it 0. Thus you are getting data from and assigning to index 0 of the array every time. The hash will grow, while the array will only contain the last item you save. | [reply] [d/l] |