internal static unsafe void FillArrays <T>(T **arrays, int collectionsCount, T[] source) where T : unmanaged { for (var i = 0; i < collectionsCount; i++) { new ReadOnlySpan <T>(source).CopyTo(new Span <T>(arrays[i], source.Length)); } }
/// <summary> /// Register an allocation /// </summary> /// <param name="count">The number of elements to be allocated</param> /// <param name="result"> /// A pointer to the storage where the beginning of the allocation will be stored. /// The address pointed to by result will be nulled when Allocate is called, and populated when Dispose is called. /// </param> /// <typeparam name="T">The element type</typeparam> /// <remarks>The alignment of T will be respected within the allocation.</remarks> public void Allocate <T>(int count, T **result) where T : unmanaged { if (result == null) { throw new ArgumentNullException("result"); } *result = null; if (count == 0) { return; } var alignment = UnsafeUtility.AlignOf <T>(); var elementSize = AlignOffset(UnsafeUtility.SizeOf <T>(), alignment); var alignedOffset = AlignOffset(m_CurrentOffset, alignment); var size = (count * elementSize) + (alignedOffset - m_CurrentOffset); m_TotalSize += size; m_LargestAlignment = Math.Max(m_LargestAlignment, alignment); m_Allocations.Add(new Allocation { Pointer = (void **)result, Offset = alignedOffset, }); m_CurrentOffset += size; }
public NonContiguousList(Allocator allocator) { mSize = 0; mCapacity = 2; mAllocator = allocator; mData = (T **)UnsafeUtility.Malloc(mCapacity * UnsafeUtility.SizeOf <IntPtr>(), UnsafeUtility.AlignOf <IntPtr>(), mAllocator); }
private GrowableBuffer(Allocator allocator, T **array) { m_Allocator = allocator; m_Array = array; m_Count = (int *)(array + 1); m_Capacity = (int *)(array + 2); }
public int Resolve <T>(T **objectReference) where T : unmanaged, IInspectable.Interface { Guid iid = typeof(T).GUID; return(Resolve(&iid, (IInspectable **)objectReference)); }
public void Dispose() { for (int i = 0; i < mSize; i++) { UnsafeUtility.Free(mData[i], mAllocator); } UnsafeUtility.Free(mData, mAllocator); mData = null; }
public static bool IsReadable <T>(T **ptr) where T : unmanaged { try { _ = *ptr; return(true); } catch { return(false); } }
/// <summary> /// Create a new GrowableBuffer /// </summary> /// <param name="allocator">The native allocator to use</param> /// <param name="initialCapacity">The initial buffer capacity</param> /// <exception cref="ArgumentOutOfRangeException">If initialCapacity <= 0</exception> public GrowableBuffer(Allocator allocator, int initialCapacity = 16) { if (initialCapacity <= 0) { throw new ArgumentOutOfRangeException(nameof(initialCapacity)); } m_Allocator = allocator; m_Array = (T **)Utility.AllocateUnsafe <IntPtr>(3, allocator); m_Count = (int *)(m_Array + 1); m_Capacity = (int *)(m_Array + 2); *m_Array = Utility.AllocateUnsafe <T>(initialCapacity, allocator); *m_Count = 0; *m_Capacity = initialCapacity; }
public void Add(T data) { if (mSize >= mCapacity) { mCapacity *= 2; var newData = (T **)UnsafeUtility.Malloc(mCapacity * UnsafeUtility.SizeOf <IntPtr>(), UnsafeUtility.AlignOf <IntPtr>(), mAllocator); UnsafeUtility.MemCpy(newData, mData, mSize * UnsafeUtility.SizeOf <IntPtr>()); UnsafeUtility.Free(mData, mAllocator); mData = newData; } var n = (T *)UnsafeUtility.Malloc(UnsafeUtility.SizeOf <T>(), UnsafeUtility.AlignOf <T>(), mAllocator); *n = data; mData[mSize++] = n; }
public void Update <T>(int sampleCount, ReadOnlySpan <T> newData1, ReadOnlySpan <T> newData2) where T : unmanaged { if (2 != format.LineCount) { throw new InvalidOperationException($"{nameof(Format)}的数据行数必须是2才能调用此方法"); } Resize(sampleCount); fixed(T *p1 = newData1) fixed(T * p2 = newData2) { T **srcPointers = stackalloc[] { p1, p2 }; FF.av_samples_copy(datas, (IntPtr *)srcPointers, 0, 0, sampleCount, format.Channels, format.SampleFormat); } }
public static T **ExpandPtrArray <T>(T **array, int currentLength, int newLength) where T : unmanaged { Assert.Check(newLength > currentLength); var oldArray = array; var newArray = MallocAndClearPtrArray <T>(newLength); // copy old contents MemCpy(newArray, oldArray, sizeof(T *) * currentLength); // free old buffer Free(oldArray); // return the new size return(newArray); }
public void Update <T>(int sampleCount, ReadOnlySpan <T> newData1, ReadOnlySpan <T> newData2, ReadOnlySpan <T> newData3, ReadOnlySpan <T> newData4, ReadOnlySpan <T> newData5, ReadOnlySpan <T> newData6, ReadOnlySpan <T> newData7) where T : unmanaged { if (7 != format.LineCount) { throw new InvalidOperationException($"{nameof(Format)}的数据行数必须是7才能调用此方法"); } Resize(sampleCount); fixed(T *p1 = newData1) fixed(T * p2 = newData2) fixed(T * p3 = newData3) fixed(T * p4 = newData4) fixed(T * p5 = newData5) fixed(T * p6 = newData6) fixed(T * p7 = newData7) { T **srcPointers = stackalloc[] { p1, p2, p3, p4, p5, p6, p7 }; FF.av_samples_copy(datas, (IntPtr *)srcPointers, 0, 0, sampleCount, format.Channels, format.SampleFormat); } }
public static int ActivateInstance <T>(IntPtr activatableClassId, T **instance) where T : unmanaged { *instance = null; IInspectable *pInspectable; int hr = RoActivateInstance(activatableClassId, &pInspectable); if (SUCCEEDED(hr)) { if (__uuidof <T>() == IID_IInspectable) { *instance = (T *)pInspectable; } else { hr = pInspectable->QueryInterface(__uuidof <T>(), (void **)instance); pInspectable->Release(); } } return(hr); }
public static T **ReallocPtrArray <T>(T **ptr, int count) where T : unmanaged { return((T **)Marshal.ReAllocHGlobal((IntPtr)ptr, (IntPtr)(sizeof(T *) * count))); }
public static T **DoublePtrArray <T>(T **array, int currentLength) where T : unmanaged { return(ExpandPtrArray(array, currentLength, currentLength * 2)); }
public static void ArrayPtrClear <T>(T **ptr, int size) where T : unmanaged { MemClear(ptr, sizeof(T *) * size); }
public static int GetActivationFactory <T>(IntPtr activatableClassId, T **factory) where T : unmanaged { return(RoGetActivationFactory(activatableClassId, __uuidof <T>(), (void **)factory)); }
public int get_Value([NativeTypeName("UINT32 *")] uint *length, [NativeTypeName("T_abi **")] T **value) { return(((delegate * unmanaged <IReferenceArray <T> *, uint *, T **, int>)(lpVtbl[6]))((IReferenceArray <T> *)Unsafe.AsPointer(ref this), length, value)); }
/// <summary>Increments the reference count for the current COM object, if any, and copies its address to a target raw pointer.</summary> /// <param name="ptr">The target raw pointer to copy the address of the current COM object to.</param> /// <returns>This method always returns <see cref="S_OK"/>.</returns> public readonly HRESULT CopyTo(T **ptr) { InternalAddRef(); *ptr = ptr_; return(S_OK); }
/// <summary> /// Creates a blittable pointer /// </summary> /// <param name="pointer"></param> public BlittablePtrPtr(T **pointer) => Pointer = pointer;
public static HRESULT GetActivationFactory <T>(HSTRING activatableClassId, T **factory) where T : unmanaged { return(RoGetActivationFactory(activatableClassId, __uuidof <T>(), (void **)factory)); }