Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7738685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:19:53+00:00 2026-06-01T08:19:53+00:00

I need to simulate a memory-hungry process. For example, On a machine with 4.0

  • 0

I need to simulate a memory-hungry process. For example, On a machine with 4.0 GiB, I need a process that would eat 3.2 GiB (give or take few MiB).

I assumed it should be as easy as:

my $mbytes = 3276;
my $huge_string = 'X' x ($mbytes * 1024 * 1024);

But I end up with process eating twice as much memory as I need it to.

  • this is same on two Windows 7 amd64 machines: one with 64-bit, the other
    with 32-bit build of Strawberry Perl

  • I’m using Sysinternals Process Explorer and watching “Private Bytes”

Of course, I could just $mbytes /= 2 (for now, I’ll probably will do that), but:

  • Is there a better way?

  • Can anyone explain why the amount is twice as length of the string?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T08:19:54+00:00Added an answer on June 1, 2026 at 8:19 am

    Code adapted from http://www.perlmonks.org/index.pl?node_id=948181, all credit goes to Perlmonk BrowserUk.

    my $huge_string = 'X';
    $huge_string x= $mbytes * 1024 * 1024;
    

    why the amount is twice as length of the string?

    Think about the order of evaluation. The right-hand expression allocates memory for your x expression, and again so does the assignment operation into your new scalar. As usual for Perl, even though the right-hand expression is not referenced anymore, the memory is not freed right away.

    Operating on an existing scalar avoids the second allocation, as shown above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to simulate multiple embedded server devices that are typically used for motor
I need to keep a list to simulate memory management. The program assigns a
I need to simulate a discrete event simulator and for that I need to
I am working on a windows application. I need to simulate Session (that we
I need to simulate a form that is similar to the interface seen during
I am testing a messaging application that uses single sign-on(SSO). I need to simulate
Scenario: over 1.5GB of text and csv files that I need to process mathematically.
I need to simulate a test scenario in which I call the getBytes() method
I need to simulate how my application will look when a user is driving
I'm writing an app where I need to simulate key press events on a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.