Perl seems to have limits but not sure why. I don't have unlimited memory in my computers

The second statement is true for everyone. And that rather shows the error in the first. You have assumed that Perl has limits when in fact all your demonstration shows is that your computer (and/or operating system) has limits. You can't put 10 litres of anything in a 1 litre bottle.

But it seems I have more than 800 MB of free memory, yet it won't allow me to create a 1 GB string.

You have 1767792kB of free memory. Even a cursory inspection shows that this will allow the allocation of 800MB x 2 but not 1GB x 2. I therefore posit that your unshown code actually uses twice the amount of RAM that you think it should. Try adding 400MB of swap space and be amazed that your program will now run with a 1GB string instead.

Well, anyway, I just wanted to know what's a safe size for a string. So, it seems that if I create a program that works with 1 GB strings, it will run on most modern machines. But if I write a program that relies on creating and working with 2GB or 4GB strings, then that might fail on some systems. I guess, the bigger the string, the fewer computers will be able to handle it.

That isn't how publicly distributed programs are written. You cannot assume anything about the platform on which your code will be run, so don't even try.


🦛


In reply to Re^3: maximum length of scalar in theory by hippo
in thread maximum length of scalar in theory by harangzsolt33

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.