コード例 #1
0
ファイル: UnsafeCode.cs プロジェクト: noah2020116/ILSpy
        private unsafe void Issue990()
        {
            Data  data = default(Data);
            Data *ptr  = &data;

            ConvertIntToFloat(ptr->Position.GetHashCode());
        }
コード例 #2
0
 public JsonStandardValidator(Allocator label = SerializationConfiguration.DefaultAllocatorLabel)
 {
     m_Label       = label;
     m_Data        = (Data *)UnsafeUtility.Malloc(sizeof(Data), UnsafeUtility.AlignOf <Data>(), label);
     m_Data->Stack = new JsonTypeStack(k_DefaultDepthLimit, label);
     Reset();
 }
コード例 #3
0
    /*
     * [DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
     * static extern IntPtr LoadLibrary(string lpFileName);
     *
     * [DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
     * static extern bool FreeLibrary(IntPtr hModule);
     *
     * [DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
     * static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName);
     */

    static void Main(string[] args)
    {
        Console.WriteLine(string.Format("Size Of UnionData : {0}", Marshal.SizeOf(typeof(UnionData))));
        Console.WriteLine(string.Format("Size Of Data : {0}", Marshal.SizeOf(typeof(Data))));

        Data *dataPtr = CreateData();

        Console.WriteLine(string.Format("FieldInteger Value : {0}", dataPtr->FieldInteger));
        Console.WriteLine(string.Format("FieldDouble Value : {0}", dataPtr->FieldDouble));

        switch (dataPtr->DataType)
        {
        case DataType.DtInteger:
        {
            Console.WriteLine(string.Format("UnionData.FieldInteger Value : {0}", dataPtr->UnionData.FieldInteger));
            break;
        }

        case DataType.DtDouble:
        {
            Console.WriteLine(string.Format("UnionData.FieldDouble Value : {0}", dataPtr->UnionData.FieldDouble));

            break;
        }

        default:
        {
            Console.WriteLine("UnKnown ?? ");
            break;
        }
        }
        RemoveData(dataPtr);
    }
コード例 #4
0
        public JsonTokenizer(int bufferSize = k_DefaultBufferSize, JsonValidationType validation = JsonValidationType.None, Allocator label = SerializationConfiguration.DefaultAllocatorLabel)
        {
            m_Label = label;
            m_Data  = (Data *)UnsafeUtility.Malloc(sizeof(Data), UnsafeUtility.AlignOf <Data>(), label);
            UnsafeUtility.MemClear(m_Data, sizeof(Data));

            m_Data->BufferSize     = bufferSize;
            m_Data->ValidationType = validation;

            if (bufferSize <= 0)
            {
                throw new ArgumentException($"Token buffer size {bufferSize} <= 0");
            }

            m_Data->JsonTokens   = (Token *)UnsafeUtility.Malloc(bufferSize * sizeof(Token), 4, label);
            m_Data->DiscardRemap = (int *)UnsafeUtility.Malloc(bufferSize * sizeof(int), 4, label);

            switch (validation)
            {
            case JsonValidationType.Standard:
                m_Data->StandardValidator = new JsonStandardValidator(label);
                break;

            case JsonValidationType.Simple:
                m_Data->SimpleValidator = new JsonSimpleValidator(label);
                break;
            }

            m_Data->TokenNextIndex   = 0;
            m_Data->TokenParentIndex = -1;
            m_Data->PrevChar         = 0;
        }
コード例 #5
0
            /// <inheritdoc/>
            public void Dispose()
            {
                m_Buffer.Dispose();
                m_Stack.Dispose();

                UnsafeUtility.Free(m_Data, m_Label);
                m_Data = null;
            }
コード例 #6
0
ファイル: LiveRange.cs プロジェクト: shadowninja108/Ryujinx
        public LiveRange(int start, int end, LiveRange next = default)
        {
            _data = Allocators.LiveRanges.Allocate <Data>();

            Start = start;
            End   = end;
            Next  = next;
        }
コード例 #7
0
 public void Dispose()
 {
     if (null != m_Data)
     {
         m_Data->Stack.Dispose();
         UnsafeUtility.Free(m_Data, m_Label);
         m_Data = null;
     }
 }
コード例 #8
0
            /// <summary>
            /// Initializes a new instance of <see cref="Unsafe"/>.
            /// </summary>
            /// <param name="initialCapacity">The initial capacity to use for the internal buffer.</param>
            /// <param name="label">The allocator label to use.</param>
            /// <param name="options">Options to define custom behaviour.</param>
            public Unsafe(int initialCapacity, Allocator label, JsonWriterOptions options = default)
            {
                m_Label = label;
                m_Data  = (Data *)UnsafeUtility.Malloc(sizeof(Data), UnsafeUtility.AlignOf <Data>(), label);
                UnsafeUtility.MemClear(m_Data, sizeof(Data));

                m_Buffer  = new NativeList <char>(initialCapacity, label);
                m_Stack   = new NativeList <State>(label);
                m_Options = options;
            }
コード例 #9
0
        public void Dispose()
        {
            if (null == m_Data)
            {
                return;
            }

            UnsafeUtility.Free(m_Data, m_Label);
            m_Data = null;
        }
コード例 #10
0
        /// <summary>
        /// Initializes a new instance of <see cref="JsonStringBuffer"/>.
        /// </summary>
        /// <param name="initialCapacity">The initial capacity to use for the internal buffer.</param>
        /// <param name="label">The allocator label to use.</param>
        public JsonStringBuffer(int initialCapacity, Allocator label)
        {
            m_Label          = label;
            m_Data           = (Data *)UnsafeUtility.Malloc(sizeof(Data), UnsafeUtility.AlignOf <Data>(), label);
            m_Data->Buffer   = null;
            m_Data->Capacity = 0;
            m_Data->Length   = 0;

            SetCapacity(initialCapacity);
        }
コード例 #11
0
        /// <inheritdoc/>
        public void Dispose()
        {
            if (m_Label != Allocator.Invalid)
            {
                UnsafeUtility.Free(m_Data->Buffer, m_Label);
            }

            UnsafeUtility.Free(m_Data, m_Label);
            m_Data = null;
        }
コード例 #12
0
        public PackedBinaryWriter(PackedBinaryStream stream, JsonTokenizer tokenizer, Allocator label)
        {
            m_Label = label;
            m_Data  = (Data *)UnsafeUtility.Malloc(sizeof(Data), UnsafeUtility.AlignOf <Data>(), label);
            UnsafeUtility.MemClear(m_Data, sizeof(Data));

            m_Stream    = stream;
            m_Tokenizer = tokenizer;
            m_Data->InputTokenNextIndex   = 0;
            m_Data->InputTokenParentIndex = -1;
        }
コード例 #13
0
        public LiveInterval(Operand local = default, LiveInterval parent = default)
        {
            _data = Allocators.LiveIntervals.Allocate <Data>();
            *_data = default;

            _data->IsFixed = false;
            _data->Local   = local;

            Parent   = parent == default ? this : parent;
            Uses     = new UseList();
            Children = new LiveIntervalList();

            FirstRange = default;
            CurrRange  = default;
            PrevRange  = default;

            SpillOffset = -1;
        }
コード例 #14
0
ファイル: Operation.cs プロジェクト: neozumm/Ryujinx
            private static Operation Make(Instruction inst, int destCount, int srcCount)
            {
                Data *data = Allocators.Operations.Allocate <Data>();

                *data = default;

                Operation result = new();

                result._data       = data;
                result.Instruction = inst;

                EnsureCapacity(ref result._data->Destinations, ref result._data->DestinationsCount, destCount);
                EnsureCapacity(ref result._data->Sources, ref result._data->SourcesCount, srcCount);

                result.Destinations.Clear();
                result.Sources.Clear();

                return(result);
            }
コード例 #15
0
        public NodeParser(JsonTokenizer tokenizer, int batchSize, Allocator label)
        {
            m_Label = label;
            m_Data  = (Data *)UnsafeUtility.Malloc(sizeof(Data), UnsafeUtility.AlignOf <Data>(), label);
            UnsafeUtility.MemClear(m_Data, sizeof(Data));

            m_Data->Tokenizer = tokenizer;
            m_Data->NodeType  = NodeType.None;

            if (batchSize < 1)
            {
                throw new ArgumentException("batchSize < 1");
            }

            m_Data->Nodes            = (int *)UnsafeUtility.Malloc(sizeof(int) * batchSize, 4, m_Label);
            m_Data->NodeLength       = batchSize;
            m_Data->NodeNextIndex    = 0;
            m_Data->TokenNextIndex   = 0;
            m_Data->TokenParentIndex = -1;
        }
コード例 #16
0
        public void Dispose()
        {
            if (null == m_Data)
            {
                return;
            }

            UnsafeUtility.Free(m_Data->JsonTokens, m_Label);
            UnsafeUtility.Free(m_Data->DiscardRemap, m_Label);

            switch (m_Data->ValidationType)
            {
            case JsonValidationType.Simple:
            case JsonValidationType.Standard:
                m_Data->Validator.Dispose();
                break;
            }

            UnsafeUtility.Free(m_Data, m_Label);
            m_Data = null;
        }
コード例 #17
0
ファイル: MemoryOperand.cs プロジェクト: rubikex/Ryujinx
        public MemoryOperand(Operand operand)
        {
            Debug.Assert(operand.Kind == OperandKind.Memory);

            _data = (Data *)Unsafe.As <Operand, IntPtr>(ref operand);
        }
コード例 #18
0
            private static Operand Make(OperandKind kind, OperandType type, ulong value, Symbol symbol = default)
            {
                Debug.Assert(kind != OperandKind.None);

                Data *data = null;

                // If constant or register, then try to look up in the intern table before allocating.
                if (kind == OperandKind.Constant || kind == OperandKind.Register)
                {
                    uint hash = (uint)HashCode.Combine(kind, type, value);

                    // Look in the next InternTableProbeLength slots for a match.
                    for (uint i = 0; i < InternTableProbeLength; i++)
                    {
                        Operand interned = new();
                        interned._data = &InternTable[(hash + i) % InternTableSize];

                        // If slot matches the allocation request then return that slot.
                        if (interned.Kind == kind && interned.Type == type && interned.Value == value && interned.Symbol == symbol)
                        {
                            return(interned);
                        }
                        // Otherwise if the slot is not occupied, we store in that slot.
                        else if (interned.Kind == OperandKind.None)
                        {
                            data = interned._data;

                            break;
                        }
                    }
                }

                // If we could not get a slot from the intern table, we allocate somewhere else and store there.
                if (data == null)
                {
                    data = Allocators.Operands.Allocate <Data>();
                }

                *data = default;

                Operand result = new();

                result._data = data;
                result.Value = value;
                result.Kind  = kind;
                result.Type  = type;

                if (kind != OperandKind.Memory)
                {
                    result.Symbol = symbol;
                }

                // If local variable, then the use and def list is initialized with default sizes.
                if (kind == OperandKind.LocalVariable)
                {
                    New(ref result._data->Assignments, ref result._data->AssignmentsCount, ref result._data->AssignmentsCapacity, 1);
                    New(ref result._data->Uses, ref result._data->UsesCount, ref result._data->UsesCapacity, 4);
                }

                return(result);
            }
コード例 #19
0
 public A(Data *data)
 {
     this.data = data;
 }
コード例 #20
0
 static extern void RemoveData(Data *dataPtr);
コード例 #21
0
 public unsafe Foo(Data *data)
 {
     Value1 = data->Value1;
     Value2 = data->Value2;
     Value3 = data->Value3;
 }
コード例 #22
0
 public unsafe static int ReturnRefDataCMember([DNNE.C99Type("struct T*")] Data *d)
 {
     return(d->c);
 }