3 ms·
Stack allocation and value allocation are different. In C#, value types can be allocated on the stack, but reference types are always allocated on the heap. The
by sz4kerto 6y ago
Stack allocation and value allocation are different. In C#, value types can be allocated on the stack, but reference types are always allocated on the heap. The OP describes an approach where reference types are stored on the stack.
- littlecranky67 6y agoBut doesn't the 'stackalloc' keyword in C# allow you to express to intentionally allocate value types on the stack?
- giulianob 6y agoI'd say ref structs are more explicitly stack allocated since they're not allowed to be boxed. Stackalloc is used to allocate arrays on the stack (or rather a block of memory).