C# Programming - Interfaces - Discussion
Discussion Forum : Interfaces - General Questions (Q.No. 3)
3.
A class implements two interfaces each containing three methods. The class contains no instance data. Which of the following correctly indicate the size of the object created from this class?
Discussion:
15 comments Page 1 of 2.
SharadBS said:
1 decade ago
As per http://stackoverflow.com/questions/3694423/size-of-a-class-object-in-net
For 32 bit it will be 24.
Quote taken from link says.
"classes have a memory minimum of 12 bytes and fields with reference types are 4 bytes on 32-bit systems and 8 bytes on 64-bit systems."
Is there any way to getting the size of heap through code?
I tried using int sizeInBytes = Marshal.SizeOf(typeof(MyClass));
It says 1 byte on 64-bit machine.
Somehow explained in http://msdn.microsoft.com/en-us/magazine/cc163791.aspx
But still I want to see the bytes through code.
For 32 bit it will be 24.
Quote taken from link says.
"classes have a memory minimum of 12 bytes and fields with reference types are 4 bytes on 32-bit systems and 8 bytes on 64-bit systems."
Is there any way to getting the size of heap through code?
I tried using int sizeInBytes = Marshal.SizeOf(typeof(MyClass));
It says 1 byte on 64-bit machine.
Somehow explained in http://msdn.microsoft.com/en-us/magazine/cc163791.aspx
But still I want to see the bytes through code.
Manas Sinha said:
1 decade ago
Its correct with 24 Bytes with 6*4 = 24 bytes way. And do not have to think about initialized or not, it is true that until initialized it will not occupy space, but this is not in the scope of the question. It says object created, does not say initialized or not!
Asish Kumar Satpathy said:
1 decade ago
The moment the object of the given class is initialized, the reference to those functions inside both the interfaces will occupy the memory. In C#.Net reference is of 4bytes.
Hence 4Bytes*3(1st interface)+4Bytes*3(2nd interface)=24Bytes
Hence 4Bytes*3(1st interface)+4Bytes*3(2nd interface)=24Bytes
Manish said:
1 decade ago
Class is initialized only then only reference is made. So, how the class will be initialized?
How class will be initialized without object creation. I mean to say how this class will be called from main method?
How class will be initialized without object creation. I mean to say how this class will be called from main method?
Parul said:
1 decade ago
In C#, for reference types (class, not struct), it is always equal to the size of a pointer (4 on 32 bit systems).
Since it has six methods in all, means size will be 6*4 = 24 bytes.
Since it has six methods in all, means size will be 6*4 = 24 bytes.
Shubham said:
1 decade ago
No memory is allocated because there are no instance are created.
Size of the instance (object) is depended how much variable are initialized in the given class and inherits classes.
Size of the instance (object) is depended how much variable are initialized in the given class and inherits classes.
Aishik said:
1 decade ago
The answer has to be 0byte....u dont know what is the predefined storage of the methods...initially it is 0....
Mukesh said:
1 decade ago
How can I understand the size of function which is created ?
Amol said:
1 decade ago
If function has size 4 then it get multiplied to 6=24
BhanuPriya Singh said:
1 decade ago
How can we identify that what is the size of method?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers