Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Reading huge file content

by moritz (Cardinal)
on Dec 06, 2007 at 13:08 UTC ( #655390=note: print w/replies, xml ) Need Help??

in reply to Reading huge file content

Well, you try to read more than 4GB data into memory, and then you copy it (perl subs use call-by-value, which makes a copy).

Do you have 8GB of memory available? Do you really want to use that much?

Replies are listed 'Best First'.
Re^2: Reading huge file content
by kyle (Abbot) on Dec 06, 2007 at 16:38 UTC

    (perl subs use call-by-value, which makes a copy)

    I don't think this is true.

    report_mem( 'program start' ); my $big = 'x' x 100_000_000; report_mem( 'after making big string' ); take_big_arg( $big ); sub take_big_arg { printf "got %d characters\n", length $_[0]; report_mem( 'passed to function' ); } sub report_mem { my ( $msg ) = @_; printf "%d %s\n", my_mem(), $msg; } sub my_mem { my ($proc_info) = grep { $_->[2] == $$ } map { [ split ] } `ps l | tail -n +2` +; return $proc_info->[6]; } __END__ 13124 program start 208444 after making big string got 100000000 characters 208444 passed to function

    The truth is Perl gives the sub aliases to the variables you pass. Common practice is to copy them after that (my ($copy) = @_), but that's something else.

      You are right, I stand corrected. And I'm a bit ashamed that I don't know such things after more than a year perl programming and half a year in the monestary..

      In the general case I wouldn't count on the fact that a subroutine doesn't copy one of its arguments, though.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2022-01-22 22:02 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (63 votes). Check out past polls.