1
 public class PersonClass
 {
        public string Name;
        public string Name1;
        public string Name2;
        public byte Age;
        public byte Age1;
        public byte Age2;
 }

I want know how much memory will be allocated on the stack if I will make such as assignment:

var newPerson = new PersonClass() // <- allocated new PersonsClass object
var pointer = newPerson // <- how match bytes will be allocated on stack?
Evgeniy Terekhin
  • 596
  • 3
  • 10
  • 2
    Does this answer your question? https://stackoverflow.com/questions/3800882/how-big-is-an-object-reference-in-net – canton7 Jan 16 '20 at 14:13
  • 1
    What you have there is a reference type, not a value type, so far less is on the stack than you might think. [This question](https://stackoverflow.com/q/605621/4137916) touches on the size aspect beyond the reference, but see also Eric Lippert's ["the stack is an implementation detail"](https://learn.microsoft.com/archive/blogs/ericlippert/the-stack-is-an-implementation-detail-part-one). There are many misconceptions programmers working in managed languages have when they port conventional wisdom from C-like languages, so the simple stack/heap dual model very often does not apply. – Jeroen Mostert Jan 16 '20 at 15:05

0 Answers0