Skip to content

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