However, Perl seems to very stubbornly insist on using 32 bits for each character.

That's not true.

ASCII characters require one byte.
Other iso-8859-1 characters require one or two bytes.
Other Unicode characters require up to four bytes. (Usually two. Practically, never four.)

Both Devel::Size and a peek at the size of the internal of the internal show differently.

$ perl -MDevel::Size=total_size -E'say total_size("A" x 1024 x 1024 x +100)' 104857636 $ perl -MDevel::Peek -E'Dump("A" x 1024 x 1024 x 100)' 2>&1 | grep LEN LEN = 104857604

The rest of the memory was used to build the string and is available for reuse. There's also the possibility that you are making a copy of the string by using it as the return value of the file. (Do you see a difference from appending ";1"? I'm getting 0 from time.)


In reply to Re: Reducing memory footprint of strings by ikegami
in thread Reducing memory footprint of strings by dansmith

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.