Runtime: Change System.Numerics.Vector<T>'s unsafe constructors' access level to public.

Created on 9 Oct 2015  路  11Comments  路  Source: dotnet/runtime

Currently Vector's constructors that accept a pointer are marked as private, e.g:
private unsafe Vector(void* dataPointer, int offset)

Please consider making them public. Because at some point we might have only the pointers themselves in our own code but rather than arrays. Recreating an array from these pointers is costly. So allow us to use this constructor directly as it is.

api-needs-work area-System.Numerics

Most helpful comment

We decided to go a different route with this. You should be able to use the Unsafe.Read<Vector<T>>(void*) method in the System.Runtime.CompilerServices.Unsafe package for this purpose. That package is also useful for a variety of other low-level pointer-based Vector manipulations. I'm going to close this issue now; please re-open or file a new issue if you think there is something that is not addressed by the current state of things.

All 11 comments

Agree!! Pretty common issue when dealing with numerical methods.

/cc @mellinoe @terrajobst @CarolEidt

This is definitely something we've wanted to do, along with increasing usability with unsafe code in general. We will still need to put this through our regular design process, but I can take care of creating a proposal and walking it through that process.

Any progress on this? i'd really like to be able to do this also :)
Maybe it doesnt have to be a void pointer but a T pointer instead? (if void* is a problem for cls compliance)

i can take a stab at it myself if you're interested

T* is not supported by C# unfortunately. So it has to be void* .

ah.. how about a byte* and size perhaps? (or maybe just a byte*)

Unfortunately I've been busy with other work and we have slowed down over the holiday season, so I don't think we will be able to get this through our review process until January. I'll post an update when that moves forward.

As for the signature, it will most likely remain void* just due to the nature of the type. Generic pointers aren't supported, and a byte* would be a bit awkward if you had some other type of pointer. The signature will most likely just be as it is in the original post:

private unsafe Vector(void* dataPointer, int offset)

The "size" of the vector is implicit from the type of vector you are creating.

sure, i was just thinking if the cls compliance was a problem, perhaps it isnt :)

We decided to go a different route with this. You should be able to use the Unsafe.Read<Vector<T>>(void*) method in the System.Runtime.CompilerServices.Unsafe package for this purpose. That package is also useful for a variety of other low-level pointer-based Vector manipulations. I'm going to close this issue now; please re-open or file a new issue if you think there is something that is not addressed by the current state of things.

New approach looks great imo!

Was this page helpful?
0 / 5 - 0 ratings