Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fill memory as fast as possible in c#

An interviewer just asked me a peculiar question I hadn't thought about before.

"How would you fill the memory of a computer as fast as possible in C#?"

I answered that I would probably use some kind of recursive function, however he pointed out I would probably get a stack overflow before filling the memory.

My question is simply, how would I fill the memory of a computer as fast as possible using C#?

like image 913
BigTallJosh Avatar asked Sep 08 '15 08:09

BigTallJosh


People also ask

How to fill a block of memory with a particular value?

memset() is used to fill a block of memory with a particular value. The syntax of memset() function is as follows :

How to increase memory of C drive in Windows 10?

Method 3: increase memory of C drive via a handy software 1 You can also use AOMEI Partition Assistant command lines to extend C drive. Just input following command lines and... 2 For the target partition is system partition, the operation will be completed under AOMEI Partition Assistant PreOS... More ...

Does your C drive keep filling up with space?

While browsing Windows forums, we find many users report their hard drive space disappearing. Although they don't store any more files on the drive, and even if they delete some files, their C drive keeps filling up. Here is a true example we extract from answers.microsoft.com:

How to use Memset () function in C?

memset () is used to fill a block of memory with a particular value. Note that ptr is a void pointer, so that we can pass any type of pointer to this function. Let us see a simple example in C to demonstrate how memset () function is used: char str [50] = "GeeksForGeeks is for programming geeks.";


2 Answers

I'd go with a fork-bomb:

while (true) Process.Start(Assembly.GetExecutingAssembly().Location);

The concept is familiar, the program endlessly starts new instances of itself.

like image 145
Andreas Eriksson Avatar answered Nov 10 '22 11:11

Andreas Eriksson


I haven't tried it, but I'd go with something like:

while(true) { Marshal.AllocHGlobal(1024); }
like image 39
Jcl Avatar answered Nov 10 '22 12:11

Jcl