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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:32:27+00:00 2026-05-28T19:32:27+00:00

What I want to do is to write a program that can generate large

  • 0

What I want to do is to write a program that can generate large files (1GB and up) filled with nothing less than random junk.

The problem is that if I try to create a file larger than 100MB my app uses more than 500MB Ram and takes for ever.

Steps I’m using:

  • use loop to generate junk data and add it to character array.
  • store all characters from the array to the variable.
  • save the data from variable to the file.

Is there any better solution for this? Maybe some shortcut?

This is what I’m working with:

namespace Fake_File_Creator
{
    public partial class MainWindow : Form
    {
        private string text;
        private List<char> stringChars;

        public MainWindow()
        {
            InitializeComponent();
        }

        private void btnNewFile_Click(object sender, EventArgs e)
        {
            sfdNewFile.Filter = "All Files|*.*";

            if (sfdNewFile.ShowDialog() == DialogResult.OK)
            {
                lblMessage.Text = "Generating data...";
                bwCreateData.RunWorkerAsync((int)nudSize.Value * 1024000);
            }
        }

        private void bwCreateData_DoWork(object sender, DoWorkEventArgs e)
        {
            var random = new Random();
            var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789 ~!@#$%^&*()_+ /.,'[];{}|:<>?";

            stringChars = new List<char>();

            for (int i = 0; i < (int)e.Argument; i++)
            {
                stringChars.Add(chars[random.Next(chars.Length)]);
            }

            text = new string(stringChars.ToArray());
        }

        void bwCreateData_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            lblMessage.Text = "Saving file...";
            bwCreateFile.RunWorkerAsync();
        }

        private void bwCreateFile_DoWork(object sender, DoWorkEventArgs e)
        {
            using (StreamWriter outfile = new StreamWriter(sfdNewFile.FileName))
            {
                outfile.Write(text);
            }
        }

        void bwCreateFile_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            lblMessage.Text = "File succesfully created...";

            text = string.Empty;
            stringChars.Clear();
            stringChars = null;
            GC.Collect(); 
        }
    }
}
  • 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-28T19:32:28+00:00Added an answer on May 28, 2026 at 7:32 pm

    Just write a ton of data to the file directly rather than saving to memory in the string “text”.

    You can call outfile.Write(“junk text”) in a loop.

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

Sidebar

Related Questions

I cannot use threads thus I want to write a server program that can
I want to write a Python program that makes PNG files. My big problem
I want to write a C++-Program that can interact/call Lua-scripts during execution. A key
I want to write a program that would print every combination of a set
I want to write a program that analyzes your fantasy baseball team and notifies
I want to write a small program that should print something like testing CPU...
I want to write a java program that acts as a user interface to
I want to write a program in C/C++ that will dynamically read a web
I want to write a program in which plays an audio file that reads
I want to write a program that could play solitaire on windows. The user

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.