T doesn't seem to exist, this seems to be the non-generic variantwhere T : unmanaged
This needs to bepublic readonly ref T Ref
readonly ref MutPtr (basically it's equivalent to this[0]. you could even implement it like that if you want)This should be a reference to the raw pointer form of its inner dimension. to forpublic ref PTRMUT* GetPinnableReference()
PtrMutPtr this would be ref readonly byte** (so that when used in a fixed statement it becomes byte***)Missed a space.public static bool operator ==(object? lh, PTRMUTPTRrh) => lh == null ? (void*)rh == null : false;
My my that's a little over 3 dimensions!public static implicit operator byte******(PTRMUTPTR ptr) => (byte******)Unsafe.AsPointer(ref Unsafe.AsRef(in ptr.Ref));
Unsafe.AsPointer does not fix the ref and therefore should only be used for known-stack pointers (i.e. the user has to be explicit about this to ensure they don't accidentally do anything dangerous)ref void so ref byte was the next best thingGetPinnableReference() not return the fully unsafe pointer?T[][][] actually work?NullPtr. basically just go over the existing manual types and see if there's anything missing from the generated ones (as this is basically what i'm doing now) where T : unmanaged public readonly ref T Refreadonly ref MutPtrthis[0] public ref PTRMUT* GetPinnableReference()PtrMutPtrref readonly byte**fixedbyte*** public static bool operator ==(object? lh, PTRMUTPTRrh) => lh == null ? (void*)rh == null : false; public static implicit operator byte******(PTRMUTPTR ptr) => (byte******)Unsafe.AsPointer(ref Unsafe.AsRef(in ptr.Ref));Unsafe.AsPointerrefref voidref byteGetPinnableReference()T[][][] IL.Emit.Ldarg_0();
IL.Emit.Ldc_I4_0();
IL.Emit.Ldelema(TypeRef.Type(typeof(T).MakePointerType()));
IL.Emit.Newobj(
MethodRef.Constructor(
TypeRef.Type(typeof(ConstPtr2D<>).MakeGenericType(typeof(T))),
TypeRef.Type(typeof(ConstPtr<>).MakeGenericType(typeof(T)).MakeByRefType())
)
);
IL.Emit.Ret();
throw IL.Unreachable(); NullPtr- public static T*[] JaggedArrayToPointerArray<T>(ReadOnlySpan<T[]> array)
+ public static T**[] JaggedArrayToPointerArray<T>(ReadOnlySpan<T[][]> array)
where T : unmanaged
{
- var ret = new T*[array.Length];
+ var ret = new T**[array.Length];
for (var i = 0; i < array.Length; i++)
{
- var handle = GCHandle.Alloc(array[i], GCHandleType.Pinned);
+ var handle = GCHandle.Alloc(JaggedArrayToPointerArray(array[i]), GCHandleType.Pinned);
var sentinel = new GCHandleSentinel(handle);
var dep = new DependentHandle(ret, sentinel);
if (!dep.IsAllocated)
{
throw new InvalidOperationException(
"Failed to allocate dependent handle to keep string alive"
);
}
sentinel.DependentHandle = dep;
- ret[i] = (T*)handle.AddrOfPinnedObject();
+ ret[i] = (T**)handle.AddrOfPinnedObject();
}
return ret;
}