Hi Guys,
Can anyone tell me what will be the size of the empty class ( Memory consumed ) in C# ??
If this is the case ,
class Sample
{
public static void main ( String args[])
{
}
}
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted Sep 19, 2013, 12:06 AM
hi,
I think, If you create object on dos/ windows 64 bit environment, the size of empty class will be 1 becoz the sizeof() function return atleast 1 byte. it is never zero. in other os it might be 2 or 4 byte.
In C++ context
please refer
http://www.geeksforgeeks.org/why-is-the-size-of-an-empty-class-not-zero-in-c/
hope this will help you.
VulpesPosted Sep 18, 2013, 11:31 AM
In .NET, every instance of a class is allocated on the managed heap and consists of two parts - overhead and data.
The size of the overhead is 8 bytes on a 32 bit system and 16 bytes on a 64 bit system.
The size of the data part is the sum of the bytes required by the individual instance fields of the class plus any padding needed for memory alignment purposes.
Even if there are no instance fields, for technical reasons there still needs to be a way to point into the data part. The CLR therefore allocates an additional byte which, for memory alignment reasons, will be effectively increased to 4 bytes on a 32 bit system and 8 bytes on a 64 bit system.
Consequently, an empty class instance will occupy a total of 12 bytes on a 32 bit system or 24 bytes on a 64 bit system.
Hemant SrivastavaPosted Sep 18, 2013, 9:55 AM
http://stackoverflow.com/questions/2331889/how-to-find-the-size-of-a-class-in-c-sharp
Iftikar HussainPosted Sep 18, 2013, 8:07 AM
Please refer the below link
http://msdn.microsoft.com/en-us/library/f42z47h2.aspx
Regards,
Iftikar