using System; class ObjectAllocator { private const int minObjects = 100; public static void Main(string[] args) { int n = 5000000; if (args.Length > 0) n = Int32.Parse(args[0]); int objects = minObjects > n ? minObjects : n; var firstObj = new TestObject(0); TestObject[] latest = new TestObject[minObjects+1]; latest[0] = firstObj; for (int o = 0; o < objects; o++) { var obj = new TestObject(o+1); if (o % (objects/10) == 0) { Console.WriteLine("Allocated object: {0} check {1}", (o+1), obj.getItem()); } latest[o%minObjects+1] = obj; int idx = ((o/2) % minObjects) + 1; var my = latest[idx]; while (my == null || my == obj) { idx /= 2; my = latest[idx]; } obj.setParent(my); } } private class TestObject { private TestObject parent; private int item; public TestObject(int item) { this.item = item; } public void setParent(TestObject parent) { this.parent = parent; } public int getItem() { return item; } } }