Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Size of an object at runtime

Tags:

c#

How do you get the size(in bytes) of an object or data structure at runtime, I know there profiler tools that do this I am only interested in doing this at runtime.

Data Structure is List<object>

I am trying to find out how much space the entire collection is taking and how much space an individual object is taking, not that there should, in theory, be a difference between the two.

like image 268
jquery auth Avatar asked Oct 07 '10 14:10

jquery auth


1 Answers

I think the sizeof operator only works for value and unmanaged types; Marshal.SizeOf might give you what you need.

like image 96
FacticiusVir Avatar answered Oct 20 '22 14:10

FacticiusVir