[CCode(cname = "atoi")] extern int string_to_int(string input); class ObjectAllocator { private const int minObjects = 100; public static void main(string[] args) { int n = 5000000; if (args.length > 1) n = string_to_int(args[1]); //Test with 50000000 or 100000000 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) { print("Allocated object: "+(o+1).to_string()+" check "+ (obj.getItem()).to_string()+"\n"); } 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; } } }