Bellad its not possible to measure an exact size used by an class or struct.
Yes you can get an idea of the in-memory size of a class or struct instance through applying the [StructLayout(LayoutKind.Sequential)] attribute on the class and call Marshal.SizeOf( ) on the type or instance.
Example: -
[StructLayout(LayoutKind.Sequential)]
public class MyClass
{
public int myField0;
public int myField1;
}
int sizeInBytes = Marshal.SizeOf(typeof(MyClass));
Note that these are examples of memory layouts for classes. The exact layout varies depending on the version of the framework, the implementation of the CLR, and whether it's a 32-bit or 64-bit application. As a program can be run on either a 32-bit or 64-bit system, the memory layout is not even known to the compiler, it's decided when the code is JIT:ed before execution.
Bellad for more details you can go through below links:
Rajeesh MenothRank #118 · 18.4K reputationPosted Oct 15, 2015, 10:32 AM EDT
You can't..Check the following reference..!!
Sujeet SumanRank #790 · 2.9K reputationPosted Oct 15, 2015, 9:58 PM EDT
Munesh SharmaRank #174 · 13.9K reputationPosted Oct 15, 2015, 11:36 PM EDT
ib belladRank #4,317 · 351 reputationPosted Oct 16, 2015, 7:32 AM EDT
Sujeet SumanRank #790 · 2.9K reputationPosted Oct 16, 2015, 8:43 AM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts