Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: scoping large arrays - newbie Q

by Aristotle (Chancellor)
on Jun 18, 2002 at 04:39 UTC ( #175267=note: print w/replies, xml ) Need Help??

in reply to scoping large arrays - newbie Q

Generally, from what I've seen so far Perl is rather good at managing memory efficiently and quickly.

Having the array persistent may speed things up if the function is being called ten thousands of times, but it also is an invitation to hogging memory, not to mention global variables just generally tend to lead to headaches. Creating a lexically scoped array a new slows things down a wee notch, but keeps the code clean and the memory footprint lean.

We're only talking 20,000 bytes of data here, that's not something I'd consider much of an array.

Two options you have if you really need the performance is passing around references instead, to keep things properly scoped without the overhead of array allocation; or using a closure like so:

{ my @not_global; sub operate_on_not_global { @not_global = whatever(); } }

Bottome line: personally, I always take the defensive approach - I can always add dirty tricks later if my clean code is not fast enough, but if I start out dirty at the scratchpad, I'll never get a handle on things and end up with a big ball of mud.

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re: scoping large arrays - newbie Q
by moof1138 (Curate) on Jun 18, 2002 at 05:08 UTC
    Thank you Screamer, that confirms what I had been getting the nagging feeling about. I had been leery of the globally scoped vars, since I would not consider using them in other languages. While I was wondering about the question in general, after I though about it for a minute, I realized that performance is not really an issue for this project - it is just an AIM bot, it winds up needing to sleep at times to keep it from hitting the AIM flood control limits anyway. I just reworked it scoping all arrays proper to their functions, and I don't feel any performance difference, really.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://175267]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2023-05-30 01:48 GMT
Find Nodes?
    Voting Booth?

    No recent polls found