Esempio n. 1
0
        public void TestNonPointers01()
        {
            var heap = new Heap();
            var values = new StackValue[]
            {
                StackValue.BuildInt(0),
                StackValue.BuildInt(1),
                StackValue.BuildInt(2)
            };

            var array1 = heap.AllocateArray(values);

            var allTypes = new List<StackValue>();
            var rawPointer = (int)array1.RawIntValue;
            for (int i = 0; i < (int)AddressType.ArrayKey; ++i)
            {
                var val = new StackValue()
                {
                    optype = (AddressType)i, 
                    opdata = rawPointer
                };

                if (!val.IsReferenceType)
                {
                    allTypes.Add(val);
                }
            }
            var array2 = heap.AllocateArray(allTypes.ToArray());

            heap.GCMarkAndSweep(new List<StackValue>() { array1}, testExecutive);

            HeapElement arrayHeapElement;
            Assert.IsTrue(heap.TryGetHeapElement(array1, out arrayHeapElement));

            heap.Free();
        }
Esempio n. 2
0
        public void TestNonPointers02()
        {
            var heap = new Heap();
            var values = new StackValue[]
            {
                StackValue.BuildInt(0),
                StackValue.BuildInt(1),
                StackValue.BuildInt(2)
            };

            var array = heap.AllocateArray(values);

            var allTypes = new List<StackValue>();
            var rawPointer = (int)array.RawIntValue;
            for (int i = 0; i < (int)AddressType.ArrayKey; ++i)
            {
                var val = new StackValue()
                {
                    optype = (AddressType)i,
                    opdata = rawPointer
                };

                if (!val.IsReferenceType)
                {
                    allTypes.Add(val);
                }
            }

            // non pointer gc root won't retain memory
            heap.GCMarkAndSweep(allTypes, testExecutive);

            HeapElement arrayHeapElement;
            Assert.IsFalse(heap.TryGetHeapElement(array, out arrayHeapElement));

            heap.Free();
        }