Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c# Span struct not working #39410

Closed
extremety1989 opened this issue Jun 9, 2020 · 5 comments
Closed

c# Span struct not working #39410

extremety1989 opened this issue Jun 9, 2020 · 5 comments

Comments

@extremety1989
Copy link

3.2 stable version
windows 10

at godot page they say " Full support c# 8 " in documentation c# 7
well i wanted to implement Span struct ,here is the link https://docs.microsoft.com/en-us/dotnet/api/system.span-1?view=netcore-3.1

@phelioz
Copy link

phelioz commented Jul 19, 2020

I it’s probably because Godot is using .NET Framework for C# right now and when using C# 8.0 with .NET Framework not all new features are supported.
It would have to be configured as a .NET Standard, .NET Core or .NET 5 app/library to use features like span and default interfaces.

@extremety1989
Copy link
Author

@phelioz i hope this feature would be avaible in godot...

@Calinou
Copy link
Member

Calinou commented Jul 19, 2020

@extremety1989 See godotengine/godot-proposals#793 and godotengine/godot-proposals#339.

As it stands right now, I think it's better to document this (probably here).

@phelioz
Copy link

phelioz commented Jul 19, 2020

Yeah I agree it would be nice. Span combined with some unsafe code could probably remove the performance issues that currently come from the marshaling. Seems maybe we will get that in 4.0, hopefully.

But until then I agree the documentation should be updated.

@raulsntos
Copy link
Member

Span<T> structs are only available in .NET Standard 2.1+ or .NET Core 2.1+ or .NET 5.0+. This is documented in the Microsoft documentation page OP linked.

Support for using netstandard2.1 as the TargetFramework was added in #40595 but new Godot projects still default to .NET Framework 4.7.2 (this is likely not going to change in 3.x since it can be considered a change that breaks compatibility, in master we are moving towards .NET 6.0 but this might not happen until 4.1).

You can manually change the TargetFramework to netstandard2.1 but be aware there are some known issues with it: https://github.com/godotengine/godot/issues?q=is%3Aissue+is%3Aopen+netstandard2.1


The supported C# version depends on the TargetFramework, some features are implemented as language features which means it doesn't need a newer framework to work, others need a newer framework to work. Which features require a newer framework is documented by Microsoft's documentation (in the Applies to section).

Span<T> is a feature that needs a newer framework version, as documented by Microsoft, since it needs a new type that is not available in older frameworks. The only way Godot can support it would be by supporting the minimum framework version required, as I mentioned earlier this is partly fixed already. Therefore, since Span<T> is a framework feature, rather than a language feature, I don't consider the statement full support for C# 8.0 to be misleading.


Also, since OP mentioned Span<T> support in particular, be aware that some features can be backported/polyfilled by using NuGet packages. The System.Memory package allows you to use Span<T> and Memory<T> in older frameworks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants