public RuntimeGlobalAccessorImpl(IAutoMemoryManagerFabric gcFabric)
        {
            var stb = new NativeStructureBuilderImpl(this, "object");

            _gcCtx = gcFabric.CreateManagerContext(this);
            if (_gcCtx.Integration != null)
            {
                _gcCtx.Integration.AugmentObjectLayout(stb);
            }

            stb.UseDefaultFieldAlignment = true;
            stb.FieldsAligmnent          = null;
            stb.StructureAlignment       = null;

            var typeIdFieldBuilder = stb.DefineField("typeId");

            typeIdFieldBuilder.Size = IntPtr.Size;

            _objectLayout    = stb.Complete();
            _typeIdFieldInfo = _objectLayout.Fields.First(f => f.Number == typeIdFieldBuilder.Number);

            this.GenerateTypes(stb);

            _memoryManager = _gcCtx.CreateManager(_systemMemoryManager, this);
        }
        private void GenerateTypes(NativeStructureBuilderImpl objectStb)
        {
            _knownTypes.Add(new IntPtr(_knownTypes.Count), _objectLayout);

            var fieldSize = new[] { 1, 2, 4, 8, 16, 32 };

            var rnd   = new Random(); // TODO: use external seed
            var count = 1000;

            for (int i = 1; i < count; i++)
            {
                var stb = new NativeStructureBuilderImpl(this, "t" + i, objectStb);

                var fieldsCount = rnd.Next(0, 40);
                var hasRefs     = false;
                for (int j = 0; j < fieldsCount; j++)
                {
                    var f = stb.DefineField("t" + i + "f" + j);

                    if (rnd.Next(0, 100) < 50)
                    {
                        f.IsReference = true;
                        hasRefs       = true;
                    }
                    else
                    {
                        f.Size = fieldSize[rnd.Next(0, fieldSize.Length)];
                    }
                }

                if (!hasRefs)
                {
                    var f = stb.DefineField("t" + i + "f" + fieldsCount);
                    f.IsReference = true;
                }

                _knownTypes.Add(new IntPtr(_knownTypes.Count), stb.Complete());
            }
        }
        public NativeStructureBuilderImpl(INativeLayoutContext ctx, string structureName, NativeStructureBuilderImpl other)
        {
            _ctx = ctx;

            this.StructureName            = structureName;
            this.UseDefaultFieldAlignment = other.UseDefaultFieldAlignment;
            this.FieldsAligmnent          = other.FieldsAligmnent;
            this.StructureAlignment       = other.StructureAlignment;

            _fields = new List <NativeStructureFieldBuilderImpl>(other._fields);
        }