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 7399215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:01:48+00:00 2026-05-29T04:01:48+00:00

I would like to write a small piece of program that launches threads, consumes

  • 0

I would like to write a small piece of program that launches threads, consumes available RAM memory in a linear fashion, until a certain level, and stops (ideally, pauses until “enough” memory is freed and continues creating threads after that, and so on.)

I tried the following, but the list.Add(new byte[]) requires contiguous RAM space and drops an OutOfMemoryException, which is NOT what I am trying to simulate.

EDIT :
I have a multi-threaded memory-hungry application that eats up a whole bunch of RAM GB’s. All I want is to isolate/reproduce that situation in “Lab conditions” to tackle it, i.e write an adaptive mem-monitoring / thread-limiter draft. I am using x64 OS an x64 Platform.
To make it clear : The result I want to see is the Task Manager Memory Monitor going up straight due to the program.

    static void Main(string[] args)
    {            
        ComputerInfo ci = new ComputerInfo();
        D("TOTAL PHYSICAL MEMORY : " + Math.Round(ci.TotalPhysicalMemory / Math.Pow(10,9),3) +" GB");

        //########### Fill Memory ###############
        var list = new List<byte[]>();

        Thread FillMem= new Thread(delegate()
        {
            while (Process.GetCurrentProcess().PrivateMemorySize64 < MAX_MEM_LEVEL)
            {
                list.Add(new byte[1024 * 10000]); //<- I Need to change this
                Thread.Sleep(100); 
            }
        });

        FillMem.Start();

        //########### Show used Memory ###############
        Thread MonitorMem = new Thread(delegate()
        {
            while (true)
            {
                D("PROCESS MEMORY : " + Math.Round(Process.GetCurrentProcess().PrivateMemorySize64 / Math.Pow(10, 6), 3) + " MB");
                Thread.Sleep(1000);
            }
        });

        MonitorMem.Start();

        Console.Read();
    }
  • 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-05-29T04:01:49+00:00Added an answer on May 29, 2026 at 4:01 am

    The question is still quite confusing; it is not clear to me what you are trying to do here and why.

    If you genuinely want to be consuming physical memory — that is, telling the operating system no, really do not use this portion of the physical RAM chip that is installed in the machine for anything other than what I say — then I would probably use the aptly-named AllocateUserPhysicalPages function from unmanaged code.

    That will then reduce the amount of physical memory that is available for other uses, forcing more virtual memory pages to go out to the page file.

    Other than making all the programs running on your machine a whole lot slower, I’m not sure what you intend to accomplish by this. Can you clarify?

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

Sidebar

Related Questions

I would like to write a small program that will run other programs. I'm
I would like to write a small program in C# which goes through my
I would like to write a program that will identify a machine( for licensing
I would like to write a small html file that would run locally and
I have a number of small algorithms that I would like to write up
I would like to write a plug-in that will allow a custom written CRM
I would like to write some scripts in python that do some automated changes
I would like to write a utility that will provide me with a relatively
I would like to write an application that will copy MP3 files to a
I would like to write the following code in c#. a) small console application

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.