in reply to Memory Usage with __DATA__

The DATA is not held in memory. DATA is just a file descriptor into the script file. It takes no more memory than reading any other file.

Replies are listed 'Best First'.
Re: Re: Memory Usage with __DATA__
by demerphq (Chancellor) on May 16, 2003 at 07:07 UTC

    Its interesting to note that the DATA file handle only gets initialized when there an __END__ or __DATA__ tag is present, if they are omitted the filehandle isnt created. Try this:

    use strict; use warnings; while (<DATA>) { print } print "--\n"; seek(DATA,0,0); while (<DATA>) { print } # uncomment the data block for this program to work #__DATA__ #test #test

    which outputs

    readline() on unopened filehandle DATA at D:\perl\scratch\test__data__ +.pl line 3. seek() on unopened filehandle DATA at D:\perl\scratch\test__data__.pl +line 7. readline() on unopened filehandle DATA at D:\perl\scratch\test__data__ +.pl line 8. --

    So presumably whatever memory consumed by the filehandle can be avoided if that makes a difference. I doubt it if it does.


    ---
    demerphq

    <Elian> And I do take a kind of perverse pleasure in having an OO assembly language...
Re: Re: Memory Usage with __DATA__
by diotalevi (Canon) on May 16, 2003 at 03:14 UTC

    But isn't the script source retained in memory?

      Yah it is, but POD isnt, and nor is anything after the __END__ / __DATA__ tags. When the parser(/lexer) hits one of these tags it stops but doesnt close the file descriptor.


      ---
      demerphq

      <Elian> And I do take a kind of perverse pleasure in having an OO assembly language...