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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:11:22+00:00 2026-05-28T22:11:22+00:00

I was wondering if it is possible for C# to write objects to the

  • 0

I was wondering if it is possible for C# to write objects to the pagefile.

I already know that a virtual machine for a .NET application is limited to allow one object to only use up 2 GB of ram and will run out of Memory long before that – even on 64-bit version of Windows.

However I need to be able to load a huge amount of strings (not 1 big one but many small ones) and was wondering if it is possible to load them and let them be written to the swap space until they are needed again (unfortunately it is not possible for me to prevent the loading of all the strings because it is forced by an application calling the code I am working on).

To prototype it I tried out to see if the following program will run out of memory as well (which it will), even though it does not try to allocate one huge string:

public static void Main()
{
        ICollection<StringBuilder> builders = new LinkedList<StringBuilder>();
        double used_ram = 2*1024*1024*1024L;
        int blocksize = 12800000;
        int blocks = (int) (used_ram/blocksize);
        for (int i = 1; i < blocks ; i++)
        {
            StringBuilder sb = new StringBuilder(blocksize/2);
            builders.Add(sb);
        }
        Console.ReadLine();
}

I was hoping that the strings would be written to the swap space and was wondering if there is any way I can force the application to do just that.

EDIT: Changed the use of swap file to pagefile (thanks for the clarifications).

Ok so to enhance my question: if the only limitation of the runtime is that ONE object can not allocate more than 2 gb of memory – why is the above code running out of memory – because the list goes over the 2 gb of memory by holding reference to all the string builders?

  • 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-28T22:11:23+00:00Added an answer on May 28, 2026 at 10:11 pm

    Short answer: no you can’t.

    Using the swap is not something applications do: the memory management system of the operating system is responsible of that.

    If you need to load more than 2GB of data in your process in one time (and not retrieve data from disk per chunks as necessary), then you have a serious design problem.


    EDIT:
    As you’re already using a 64-bit OS, make sure you’re compiling your application for x64 platforms (or AnyCPU) and your application is not running as a 32-bit process using WOW64.

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

Sidebar

Related Questions

I was sitting here wondering if it's possible to write a greasemonkey script that
Is it possible in VB.NET to easily write an event handler that will handle
I was wondering if i could possible write an app, that could be a
I could easily write one, but I'm wondering if there is already a standard
I was wondering - how are objects stored int the memory? I already know
i was wondering if it was possible to write my own firmware that will
I was wondering ( if possible ) if there was a program/tool/utility that when
I was wondering - is it possible to change files that are stored on
Possible Duplicate: Can you write object oriented code in C? I'm wondering if it's
I'm wondering if it's possible to write a passthrough extension method for IQueryable which

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.