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

Remove [FixedAddressValueType]. #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

teo-tsirpanis
Copy link

It has no effect for this use case and blocks the assembly from being loaded in unloadable AssemblyLoadContexts.

Fun fact: These were the only uses of this attribute on GitHub outside of .NET itself. 😅

@glenn-slayden
Copy link

These were the only uses of this attribute on GitHub outside of .NET itself...

Really? I use FixedAddressValueTypeAttribute all the time, typically for read-only reference tables or data that will be referenced for the duration/lifetime of the CLR session.

Obviously, GC and managed memory are the cat's meow, but for some cases, it's nice to have a permanent nint value which lets you immediately indirect into (pointer arithmetic!)--and fetch into--the exact piece data with no muss or fuss. Grab-it-and-go? I like to think, although some purists would probably think of it as more of a smash 'n grab?

@teo-tsirpanis
Copy link
Author

read-only reference tables or data that will be referenced for the duration/lifetime of the CLR session

There is a better way to do this. Consider this code:

using System;

public class C
{
    public ReadOnlySpan<byte> Data => new byte[3] { 1, 2, 3 };
}

It might seem that accessing Data will allocate a byte array but it won't. The span will point directly to the data section of the assembly.

This has worked with byte-sized values since quite some time and starting with dotnet/roslyn#61414 it can emit optimized code for arrays of bigger primitives.

@glenn-slayden

This comment was marked as off-topic.

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

Successfully merging this pull request may close these issues.

2 participants