Example #1
0
 private static void DeleteTestObj(IHeapConnector obj)
 {
     obj.AccessField(TESTTYPE_BYTEARRAY_IDX).Dereference().DeleteArray();
     obj.AccessField(TESTTYPE_SHORTARRAY_IDX).Dereference().DeleteArray();
     obj.AccessField(TESTTYPE_INTARRAY_IDX).Dereference().DeleteArray();
     obj.AccessField(TESTTYPE_LONGARRAY_IDX).Dereference().DeleteArray();
     obj.AccessField(TESTTYPE_NUMARRAY_IDX).Dereference().DeleteArray();
     obj.AccessField(TESTTYPE_INTVECTARRAY_IDX).Dereference().DeleteArray();
     obj.AccessField(TESTTYPE_NUMVECTARRAY_IDX).Dereference().DeleteArray();
     obj.AccessField(TESTTYPE_INTRECTARRAY_IDX).Dereference().DeleteArray();
     obj.AccessField(TESTTYPE_NUMRECTARRAY_IDX).Dereference().DeleteArray();
     obj.Delete();
 }
Example #2
0
        static void TestSimulationHeap()
        {
            List <HeapType> testMetadata = new List <HeapType>()
            {
                new HeapType("Unit", new List <KeyValuePair <string, string> >()
                {
                    new KeyValuePair <string, string>("HitPoints", "short"),
                    new KeyValuePair <string, string>("TestArray", "int*"),
                    new KeyValuePair <string, string>("TestPtrArray", "Building**"),
                    new KeyValuePair <string, string>("TestPtr", "Building*"),
                }),
                new HeapType("Building", new List <KeyValuePair <string, string> >()
                {
                    new KeyValuePair <string, string>("HitPoints", "short"),
                    new KeyValuePair <string, string>("BuildStatus", "short"),
                }),
            };

            IHeapManagerInternals heapMgr = new HeapManager(testMetadata);

            IHeapType unitType              = heapMgr.GetHeapType("Unit");
            int       UNIT_HP_IDX           = unitType.GetFieldIdx("HitPoints");
            short     UNIT_HP_TID           = unitType.GetFieldTypeID("HitPoints");
            int       UNIT_TESTARRAY_IDX    = unitType.GetFieldIdx("TestArray");
            short     UNIT_TESTARRAY_TID    = unitType.GetFieldTypeID("TestArray");
            int       UNIT_TESTPTRARRAY_IDX = unitType.GetFieldIdx("TestPtrArray");
            short     UNIT_TESTPTRARRAY_TID = unitType.GetFieldTypeID("TestPtrArray");
            int       UNIT_TESTPTR_IDX      = unitType.GetFieldIdx("TestPtr");
            short     UNIT_TESTPTR_TID      = unitType.GetFieldTypeID("TestPtr");

            IHeapType buildingType             = heapMgr.GetHeapType("Building");
            int       BUILDING_HP_IDX          = buildingType.GetFieldIdx("HitPoints");
            short     BUILDING_HP_TID          = buildingType.GetFieldTypeID("HitPoints");
            int       BUILDING_BUILDSTATUS_IDX = buildingType.GetFieldIdx("BuildStatus");
            short     BUILDING_BUILDSTATUS_TID = buildingType.GetFieldTypeID("BuildStatus");

            Stopwatch watch = new Stopwatch();

            watch.Start();

            for (int j = 0; j < 100000; j++)
            {
                IHeapConnector unit      = heapMgr.New(unitType.ID);
                IHeapConnector building0 = heapMgr.New(buildingType.ID);
                IHeapConnector building1 = heapMgr.New(buildingType.ID);

                ((IValueWrite <short>)building0.AccessField(BUILDING_HP_IDX)).Write(100);
                ((IValueWrite <short>)building0.AccessField(BUILDING_BUILDSTATUS_IDX)).Write(50);
                ((IValueWrite <short>)building1.AccessField(BUILDING_HP_IDX)).Write(50);
                ((IValueWrite <short>)building1.AccessField(BUILDING_BUILDSTATUS_IDX)).Write(100);

                ((IValueWrite <short>)unit.AccessField(UNIT_HP_IDX)).Write(88);
                unit.AccessField(UNIT_TESTPTR_IDX).PointTo(building0);

                unit.AccessField(UNIT_TESTARRAY_IDX).PointTo(heapMgr.NewArray(heapMgr.GetHeapType("int").ID, 5));
                for (int i = 0; i < 5; ++i)
                {
                    ((IValueWrite <int>)unit.AccessField(UNIT_TESTARRAY_IDX).Dereference().AccessArrayItem(i)).Write(i);
                }

                unit.AccessField(UNIT_TESTPTRARRAY_IDX).PointTo(heapMgr.NewArray(heapMgr.GetHeapType("Building*").ID, 5));
                unit.AccessField(UNIT_TESTPTRARRAY_IDX).Dereference().AccessArrayItem(0).PointTo(building0);
                unit.AccessField(UNIT_TESTPTRARRAY_IDX).Dereference().AccessArrayItem(1).PointTo(building1);

                unit.AccessField(UNIT_TESTARRAY_IDX).Dereference().DeleteArray();
                unit.AccessField(UNIT_TESTPTRARRAY_IDX).Dereference().DeleteArray();
                unit.Delete();
                building0.Delete();
                building1.Delete();
            }

            watch.Stop();
            // TODO: test heap saving/loading
        }