user978122
user978122

Reputation: 5771

How to get Size of a object (class, structure) in c#

I am attempting to perform a perverse memory trick by calculating the size of an object (one of many in a serial fashion), so I can jump forward in the memory stream to the next one.

This is for a managed class. I've seen reference to sizeof and Mashal.SizeOf, but they appeared in reference to unmanaged types or value types.

So, does anyone know a way to do this at runtime, or should I break out the calculator and it do it manually in the code?

Upvotes: 3

Views: 1852

Answers (1)

Mustafa Ekici
Mustafa Ekici

Reputation: 7480

You cant get size of object if you dont use unsafe coding (marshal)
You can use a tool like:

CLR Profiler
VSTS Profiler
.NET Memory Profiler

Upvotes: 4

Related Questions