Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Anonymous Data Structures

by lwicks (Friar)
on Jun 01, 2007 at 15:56 UTC ( [id://618788]=note: print w/replies, xml ) Need Help??


in reply to Re: Anonymous Data Structures
in thread Anonymous Data Structures

Hi Herkum, So colour me a noob, but what you are saying is in your first example we are chewing up memory creating a copy of $counter. Whereas in the second example we are pointing to the original. The implication being that example two is more efficient/faster/leet? Is that right. Lance

Kia Kaha, Kia Toa, Kia Manawanui!
Be Strong, Be Brave, Be perservering!

Replies are listed 'Best First'.
Re^3: Anonymous Data Structures
by Herkum (Parson) on Jun 01, 2007 at 21:12 UTC

    your first example we are chewing up memory creating a copy of $counter

    Correct.

    in the second example we are pointing to the original. The implication being that example two is more efficient/faster/leet? Is that right.

    Correct as well. The example I used does not really offer any performance benefits because it is too small.

    Lets supposed you have a million element array. In the first example you would, create 2 copies of that million element array in your program(So it takes more memory). You would also be passing million values to and from the function(so it would be slower).

    If you use a reference you have one copy of that array. You only passing a single value to the function. This can be provide enormous performances benefits when working with a large amount of data.

    There are times you want to make a copy because you don't want to change the original data. But if you are modifying the original values you should use references.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2024-03-28 12:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found