Skip to content

Instantly share code, notes, and snippets.

@slang25 slang25/mem.cs forked from ayende/mem.cs
Last active Sep 28, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.