Skip to content

Instantly share code, notes, and snippets.

@slang25
Forked from ayende/mem.cs
Last active September 28, 2018 09:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slang25/39acdb0f404bad691e72f450d9266885 to your computer and use it in GitHub Desktop.
Save slang25/39acdb0f404bad691e72f450d9266885 to your computer and use it in GitHub Desktop.
class Program
{
static ManualResetEvent _produce = new ManualResetEvent(false);
static ManualResetEvent _consume = new ManualResetEvent(false);
private static void Run()
{
while (true)
{
_produce.WaitOne();
_produce.Reset();
ComputeHash();
Console.WriteLine("Done");
_consume.Set();
}
}
[MethodImpl(MethodImplOptions.NoInlining)]
static void ComputeHash()
{
var b = new byte[1024 * 1024 * 128];
MD5.Create().ComputeHash(b);
}
static void Main(string[] args)
{
Console.WriteLine("Press enter to start");
Console.ReadLine();
new Thread(Run)
{
IsBackground = true,
}.Start();
while (true)
{
_produce.Set();
_consume.WaitOne();
_consume.Reset();
GC.Collect(2);
GC.WaitForPendingFinalizers();
Console.WriteLine(GC.GetTotalMemory(true));
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment