コード例 #1
0
    void RunTest()
    {
        void *ptr = MUnsafeUtility.GetManagedPtr(this);
        Test  t   = MUnsafeUtility.GetObject <Test>(ptr);

        Debug.Log(f**k);
    }
コード例 #2
0
    public int ConcurrentAdd(ref T value, object lockerObj)
    {
        int last = Interlocked.Increment(ref data->count);

        //Concurrent Resize
        if (last > data->capacity)
        {
            lock (lockerObj)
            {
                if (last > data->capacity)
                {
                    int   newCapacity = data->capacity * 2;
                    void *newPtr      = MUnsafeUtility.Malloc <T>(sizeof(T) * newCapacity, data->allocator);
                    UnsafeUtility.MemCpy(newPtr, data->ptr, sizeof(T) * data->capacity);
                    UnsafeUtility.Free(data->ptr, data->allocator);
                    data->ptr      = newPtr;
                    data->capacity = newCapacity;
                }
            }
        }
        last--;
        T *ptr = (T *)data->ptr;

        *(ptr + last) = value;
        return(last);
    }
コード例 #3
0
 public NativeList(int count, int capacity, Allocator alloc)
 {
     isCreated       = true;
     data            = MUnsafeUtility.Malloc <NativeListData>(sizeof(NativeListData), alloc);
     data->count     = count;
     data->capacity  = capacity;
     data->allocator = alloc;
     data->ptr       = MUnsafeUtility.Malloc <T>(sizeof(T) * capacity, alloc);
 }
コード例 #4
0
 public NativeList_ulong(int capacity, Allocator alloc)
 {
     isCreated       = true;
     capacity        = Mathf.Max(capacity, 1);
     data            = MUnsafeUtility.Malloc <NativeListData>(sizeof(NativeListData), alloc);
     data->count     = 0;
     data->capacity  = capacity;
     data->allocator = alloc;
     data->ptr       = MUnsafeUtility.Malloc <ulong>(sizeof(ulong) * capacity, alloc);
 }
コード例 #5
0
    public void AddCapacityTo(int capacity)
    {
        if (capacity <= data->capacity)
        {
            return;
        }
        data->capacity = capacity;
        void *newPtr = MUnsafeUtility.Malloc <ulong>(sizeof(ulong) * data->capacity, data->allocator);

        UnsafeUtility.MemCpy(newPtr, data->ptr, sizeof(ulong) * data->count);
        UnsafeUtility.Free(data->ptr, data->allocator);
        data->ptr = newPtr;
    }
コード例 #6
0
    private void Resize()
    {
        if (data->count <= data->capacity)
        {
            return;
        }
        data->capacity *= 2;
        void *newPtr = MUnsafeUtility.Malloc <ulong>(sizeof(ulong) * data->capacity, data->allocator);

        UnsafeUtility.MemCpy(newPtr, data->ptr, sizeof(ulong) * data->count);
        UnsafeUtility.Free(data->ptr, data->allocator);
        data->ptr = newPtr;
    }
コード例 #7
0
    private void Resize()
    {
        if (data->count <= data->capacity)
        {
            return;
        }
        data->capacity = Mathf.Max(data->capacity + 1, (int)(data->capacity * 1.5));
        void *newPtr = MUnsafeUtility.Malloc <T>(sizeof(T) * data->capacity, data->allocator);

        UnsafeUtility.MemCpy(newPtr, data->ptr, sizeof(T) * data->count);
        UnsafeUtility.Free(data->ptr, data->allocator);
        data->ptr = newPtr;
    }
コード例 #8
0
    private void ResizeToCount()
    {
        if (data->count <= data->capacity)
        {
            return;
        }
        int lastcapacity = data->capacity;

        data->capacity = data->count;
        void *newPtr = MUnsafeUtility.Malloc <T>(sizeof(T) * data->capacity, data->allocator);

        UnsafeUtility.MemCpy(newPtr, data->ptr, sizeof(T) * lastcapacity);
        UnsafeUtility.Free(data->ptr, data->allocator);
        data->ptr = newPtr;
    }
コード例 #9
0
    public NativeList(int count, Allocator alloc, T defaultValue)
    {
        isCreated       = true;
        data            = MUnsafeUtility.Malloc <NativeListData>(sizeof(NativeListData), alloc);
        data->count     = count;
        data->capacity  = count;
        data->allocator = alloc;
        data->ptr       = MUnsafeUtility.Malloc <T>(sizeof(T) * count, alloc);
        T *add = (T *)data->ptr;

        for (int i = 0; i < count; ++i)
        {
            add[i] = defaultValue;
        }
    }
コード例 #10
0
    public void AddCapacityTo(int capacity)
    {
        if (capacity <= data->capacity)
        {
            return;
        }
        int lastcapacity = data->capacity;

        data->capacity = capacity;
        void *newPtr = MUnsafeUtility.Malloc <T>(sizeof(T) * data->capacity, data->allocator);

        UnsafeUtility.MemCpy(newPtr, data->ptr, sizeof(T) * lastcapacity);
        UnsafeUtility.Free(data->ptr, data->allocator);
        data->ptr = newPtr;
    }
コード例 #11
0
    private void ResizeToCount()
    {
        if (data->count <= data->capacity)
        {
            return;
        }
        int oldCap = data->capacity;

        data->capacity = data->count;
        void *newPtr = MUnsafeUtility.Malloc <ulong>(sizeof(ulong) * data->capacity, data->allocator);

        UnsafeUtility.MemCpy(newPtr, data->ptr, sizeof(ulong) * oldCap);
        UnsafeUtility.Free(data->ptr, data->allocator);
        data->ptr = newPtr;
    }
コード例 #12
0
    private void ResizeToCount()
    {
        if (data->count <= data->capacity)
        {
            return;
        }
        int oldCap = data->capacity;

        data->capacity = Mathf.Max((int)(oldCap * 1.2f), data->count);
        void *newPtr = MUnsafeUtility.Malloc <T>(sizeof(T) * data->capacity, data->allocator);

        UnsafeUtility.MemCpy(newPtr, data->ptr, sizeof(T) * oldCap);
        UnsafeUtility.Free(data->ptr, data->allocator);
        data->ptr = newPtr;
    }