Skip to content
Discussion options

You must be logged in to vote

See: https://learn.microsoft.com/en-us/archive/msdn-magazine/2018/january/csharp-all-about-span-exploring-a-new-net-mainstay

These references are called interior pointers, and tracking them is a relatively expensive operation for the .NET runtime’s garbage collector. As such, the runtime constrains these refs to only live on the stack, as it provides an implicit low limit on the number of interior pointers that might be in existence.

As a result, Span instances can only live on the stack, not on the heap. This means you can’t box spans (and thus can’t use Span with existing reflection invoke APIs, for example, as they require boxing). It means you can’t have Span fields in classes, or …

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@HaloFour
Comment options

@nathan130200
Comment options

@nathan130200
Comment options

@HaloFour
Comment options

@nathan130200
Comment options

Answer selected by nathan130200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants