public void Nullable()
        {
            TypeLayout.PrintLayout <Nullable <bool> >();
            var typeLayout = TypeLayout.GetLayout <Nullable <bool> >(includePaddings: true);

            Assert.AreEqual(Unsafe.SizeOf <Nullable <bool> >(), typeLayout.Size);
        }
Exemplo n.º 2
0
        public void Print_NotAlignedClass()
        {
            TypeLayout.PrintLayout <model>();
            model u = new model();

            u.FunC();
        }
Exemplo n.º 3
0
        ///////////////////////////////////////////////////////////////////////
        // Listings 13-79, 13-81
        static void Main(string[] args)
        {
            Console.WriteLine(sizeof(Test1));
            Console.WriteLine(sizeof(Test2));
            //Console.WriteLine(sizeof(Test1o));
            //Console.WriteLine(sizeof(Test2o));
            Console.WriteLine(Unsafe.SizeOf <Test3>());
            Console.WriteLine(Unsafe.SizeOf <Test4>());

            TypeLayout.PrintLayout <SomeClass>();
            TypeLayout layout = TypeLayout.GetLayout <AlignedDouble>();

            Console.WriteLine($"Total size {layout.FullSize}B with {layout.Paddings}B padding.");
            foreach (var fieldBase in layout.Fields)
            {
                switch (fieldBase)
                {
                case FieldLayout field: Console.WriteLine($"{field.Offset} {field.Size} {field.FieldInfo.Name}"); break;

                case Padding padding: Console.WriteLine($"{padding.Offset} {padding.Size} Padding"); break;
                }
            }
            //TypeLayout.PrintLayout<UnalignedDoubleExplicit>();
            //var o = new AlignedDouble();
            //Console.ReadLine();
            //GC.KeepAlive(o);
            Console.ReadLine();
        }
Exemplo n.º 4
0
 public void PrivateMemoryLayout()
 {
     TypeLayout.PrintLayout <PrivateMemory <long> >(recursively: false);
     TypeLayout.PrintLayout <PrivateMemory <byte> >(recursively: false);
     TypeLayout.PrintLayout <PrivateMemory <object> >(recursively: false);
     var layout = TypeLayout.GetLayout <PrivateMemory <long> >();
 }
Exemplo n.º 5
0
 static void Main(string[] args)
 {
     TypeLayout.PrintLayout <Struct1>();
     TypeLayout.PrintLayout <Struct2>();
     TypeLayout.PrintLayout <Struct3>();
     TypeLayout.PrintLayout <Struct4>();
 }
Exemplo n.º 6
0
 public void PrintClassMultipleByteWrappersLayout()
 {
     AssertNonRecursiveWithPadding <Slot <long> >();
     // In this case every field aligned on the pointer boundaries
     TypeLayout.PrintLayout <Slot <long> >();
     //Assert.That(TypeLayout.GetLayout<Slot>().Size, Is.EqualTo(24));
 }
Exemplo n.º 7
0
        public void PrintStructMultipleByteWrappersLayout()
        {
            AssertNonRecursiveWithPadding <StructMultipleByteWrappers>();

            // If the layout is sequential, then structs are aligned properly with no paddings
            TypeLayout.PrintLayout <StructMultipleByteWrappers>();
        }
Exemplo n.º 8
0
 public void CorePoolsLayout()
 {
     TypeLayout.PrintLayout <MPMCPoolCore <DummyPoolable> >();
     TypeLayout.PrintLayout <ObjectPoolCore <DummyPoolable> >();
     TypeLayout.PrintLayout <LockedObjectPoolCore <DummyPoolable> >();
     TypeLayout.PrintLayout <ObjectPool <DummyPoolable> .RightPaddedObjectPoolCore>();
     TypeLayout.PrintLayout <LockedObjectPool <DummyPoolable> .RightPaddedLockedObjectPoolCore>();
 }
        public void NullableLongByteStruct()
        {
            TypeLayout.PrintLayout <Nullable <LongByteStruct> >();
            var typeLayout = TypeLayout.GetLayout <Nullable <LongByteStruct> >(includePaddings: true);
            var size       = Unsafe.SizeOf <Nullable <LongByteStruct> >();

            Assert.AreEqual(typeLayout.Size, size);
        }
Exemplo n.º 10
0
        protected void AssertNonRecursiveWithPadding <T>() where T : struct
        {
            TypeLayout.PrintLayout <T>();
            var structLayout = UnsafeLayout.GetLayout <T>(recursive: false);
            var typeLayout   = TypeLayout.GetLayout <T>(includePaddings: true);

            CollectionAssert.AreEquivalent(typeLayout.Fields, structLayout);
            Assert.AreEqual(Unsafe.SizeOf <T>(), typeLayout.Size);
        }
        public void Vector2AsPrimitive()
        {
            TypeLayout.PrintLayout <Vector2>();
            var structLayout = UnsafeLayout.GetFieldsLayout <Vector2>(considerPrimitives: new HashSet <Type> {
                typeof(Vector2)
            });

            Assert.AreEqual(1, structLayout.Count());
        }
Exemplo n.º 12
0
        public void Print_WithVolatile()
        {
            AssertNonRecursive <WithVolatile>();

            TypeLayout.PrintLayout <WithVolatile>();
            var typeLayout = TypeLayout.GetLayout <WithVolatile>();

            Assert.That(typeLayout.FullSize, Is.EqualTo(16));
        }
        public void UnsafeStructRecursive()
        {
            TypeLayout.PrintLayout <WithNestedUnsafeStruct>();
            var structLayout = UnsafeLayout.GetLayout <WithNestedUnsafeStruct>();

            Assert.AreEqual(1, structLayout.Count());
            Assert.AreEqual(0, structLayout[0].Offset);
            Assert.AreEqual(33, structLayout[0].Size);
        }
        public void Print_WithVolatile()
        {
            Console.WriteLine(Marshal.SizeOf <WithVolatile>());

            TypeLayout.PrintLayout <WithVolatile>();

            var layout = TypeLayout.GetLayout <WithVolatile>();

            Assert.That(layout.FullSize, Is.EqualTo(16));
        }
Exemplo n.º 15
0
        public static void Main()
        {
            //BenchmarkRunner.Run<RingBufferBenchmarks>();

            TypeLayout.PrintLayout <Sequence>();
            TypeLayout.PrintLayout <RingBuffer <object> >();
            TypeLayout.PrintLayout <SingleProducerSequencer>();

            Console.ReadLine();
        }
        public void WithNullableIntStructRecursive()
        {
            TypeLayout.PrintLayout <WithNullableIntStruct>();
            var unsafeLayout = UnsafeLayout.GetFieldsLayout <WithNullableIntStruct>(recursive: true);

            Assert.AreEqual(2, unsafeLayout.Count());
            Assert.AreEqual(0, unsafeLayout[0].Offset);
            Assert.AreEqual(1, unsafeLayout[0].Size);
            Assert.AreEqual(4, unsafeLayout[1].Offset);
            Assert.AreEqual(4, unsafeLayout[1].Size);
        }
        public void GenericGenericStructIntFields()
        {
            TypeLayout.PrintLayout <GenericStruct <GenericStruct <int> > >();
            var structLayout = UnsafeLayout.GetFieldsLayout <GenericStruct <GenericStruct <int> > >(recursive: true);

            Assert.AreEqual(3, structLayout.Count());
            Assert.AreEqual(0, structLayout[0].Offset);
            Assert.AreEqual(1, structLayout[0].Size);
            Assert.AreEqual(4, structLayout[1].Offset);
            Assert.AreEqual(1, structLayout[1].Size);
            Assert.AreEqual(8, structLayout[2].Offset);
            Assert.AreEqual(4, structLayout[2].Size);
        }
        public void WithNullableBoolBoolStructStructRecursive()
        {
            TypeLayout.PrintLayout <WithNullableBoolBoolStructStruct>();
            var unsafeLayout = UnsafeLayout.GetFieldsLayout <WithNullableBoolBoolStructStruct>(recursive: true);

            Assert.AreEqual(3, unsafeLayout.Count());
            Assert.AreEqual(0, unsafeLayout[0].Offset);
            Assert.AreEqual(1, unsafeLayout[0].Size);
            Assert.AreEqual(typeof(bool), unsafeLayout[0].FieldInfo.FieldType);
            Assert.AreEqual(1, unsafeLayout[1].Offset);
            Assert.AreEqual(1, unsafeLayout[1].Size);
            Assert.AreEqual(typeof(bool), unsafeLayout[1].FieldInfo.FieldType);
            Assert.AreEqual(2, unsafeLayout[2].Offset);
            Assert.AreEqual(1, unsafeLayout[2].Size);
            Assert.AreEqual(typeof(bool), unsafeLayout[2].FieldInfo.FieldType);
        }
Exemplo n.º 19
0
        static void Main(string[] args)
        {
            TypeLayout.PrintLayout(
                typeof(PatternsAndConcepts.DummyModels.Product));


            Console.WriteLine(" ");

            TypeLayout.PrintLayout(
                typeof(PatternsAndConcepts.DummyModels.ProductStruct));

            Console.WriteLine(" ");

            TypeLayout.PrintLayout(
                typeof(PatternsAndConcepts.DummyModels.ProductStructLayoutAuto));

            Console.WriteLine(" ");

            TypeLayout.PrintLayout(
                typeof(PatternsAndConcepts.DummyModels.ProductStructLayoutSequential));
        }
Exemplo n.º 20
0
        static void Main(string[] args)
        {
            BenchmarkRunner.Run <BranchPrediction>();
            BenchmarkRunner.Run <BranchPrediction2>();

            BenchmarkRunner.Run <CacheMissSequentialAccess>();
            BenchmarkRunner.Run <CacheMissTiling>();

            BenchmarkRunner.Run <CacheInvalidation>();
            BenchmarkRunner.Run <CacheInvalidation2>();

            BenchmarkRunner.Run <SIMD>();
            BenchmarkRunner.Run <SIMD2>();

            BenchmarkRunner.Run <AoSvsSoA>();
            TypeLayout.PrintLayout <AoSvsSoA.VectorThatDontFitCacheLine>(true);
            TypeLayout.PrintLayout <AoSvsSoA.VectorThatFitCacheLine>(true);

            BenchmarkRunner.Run <AoCvsAoS>();
            TypeLayout.PrintLayout <AoCvsAoS.ClassThatDontFitCacheLine>(true);
            TypeLayout.PrintLayout <AoCvsAoS.StructThatFitCacheLine>(true);

            BenchmarkRunner.Run <ECS>();
        }
 public void GetLayoutForTwoSpecificTypes()
 {
     TypeLayout.PrintLayout(typeof(Test1));
     TypeLayout.PrintLayout(typeof(Test2));
 }
 public void Print_StructWithExplicitLayout()
 {
     TypeLayout.PrintLayout <ClassWithExplicitLayout>();
 }
 public void Print_StructWithExplicitLayoutAndOffsetForFirstField()
 {
     TypeLayout.PrintLayout <ClassWithExplicitLayoutAndOffsetForFirstField>();
 }
Exemplo n.º 24
0
 public void AsyncValueTaskStateMachineLayout()
 {
     var(_, valueTask) = GetStateMachineTypes();
     TypeLayout.PrintLayout(valueTask);
 }
Exemplo n.º 25
0
 public void AsyncTaskStateMachineLayout()
 {
     var(taskStateMachine, _) = GetStateMachineTypes();
     TypeLayout.PrintLayout(taskStateMachine);
 }
 public void GenericStructInt()
 {
     TypeLayout.PrintLayout <GenericStruct <int> >();
     AssertNonRecursiveWithPadding <GenericStruct <int> >();
 }
Exemplo n.º 27
0
 public void OffHeapMemoryLayout()
 {
     TypeLayout.PrintLayout <PrivateMemory <byte> >();
 }
Exemplo n.º 28
0
 public void ArrayMemoryLayout()
 {
     TypeLayout.PrintLayout <ArrayMemory <byte> >();
 }
Exemplo n.º 29
0
 public void Print_NotAlignedClass()
 {
     TypeLayout.PrintLayout <NotAlignedClass>();
 }
Exemplo n.º 30
0
 public void RetainableMemoryLayout()
 {
     TypeLayout.PrintLayout <DummyRetainableMemory>();
 }