Project · Memory
Checked admission memory budgets
Compare explicit payload owners and reject invalid capacity before arithmetic.
All C# source files below are loaded together in the playground. Files written by a run live in its virtual directory.
Program.cs
Console.WriteLine($"bounded-KiB:{Budget.KiB(4,8,256,2)}");
Console.WriteLine($"overloaded-KiB:{Budget.KiB(4,800,256,2)}");
try { Budget.KiB(0,8,256,2); } catch (ArgumentOutOfRangeException) { Console.WriteLine("workers:rejected"); }
Budget.cs
public static class Budget { public static long KiB(int workers,int queued,int payloadKiB,int copies) { if(workers<1 || queued<0 || payloadKiB<0 || copies<1) throw new ArgumentOutOfRangeException(); return checked(((long)workers+queued)*payloadKiB*copies); } }