c# - Memory allocation on object creation -


how memory allocated in stack in heap when instantiate class/struct student?

i guess id = 4 bytes reference (32 bit machine) , name = 4 bytes reference , facultyadvisor = 4 bytes reference. totally 12 bytes in stack , actual size in heap. heap size may vary depends upon value assign fields(id, name, facultyadvisor) uses object obj(student obj = new student())

the same struct right?

public class student { int id; string name; professor facultyadvisor; }  public struct student { int id; string name; professor facultyadvisor; } 

assuming 32 bit clr (references 64 bit on 64 bit clr) , taking account heap allocation student

class student{} class professor{}

  • stack: 4 bytes
  • heap: 4 bytes (int) + 4 bytes (professor reference) + 4 bytes (string reference) + 12 bytes (object header) = 24 bytes

class student{} struct professor{}

  • stack: 4 bytes
  • heap: 4 bytes (int) + size of processor + 4 bytes (string reference) + 12 bytes (object header) = ?? bytes

struct student{} class professor{}

  • stack: 4 bytes (int) + 4 bytes (string reference) + 4 bytes (professor reference) = 12 bytes
  • heap: 0 bytes

struct student{} struct professor{}

  • stack: 4 bytes (int) + 4 bytes (string reference) + size of professor = ?? bytes
  • heap: 0 bytes

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -