0

I have some custom types (the type cannot be serialized, so I cannot use BinaryFormatter and MemoryStream to get the bytes needed to hols this object) and I cannot use Marshal.SizeOf(). Is there other way to get the memory needed by a object? The object can be an instance of a custom type or an array of a custom type objects.

PS: It's not accurate to get the memory at the begining and at the end to obtain the memory needed because other processes runs in the background

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
Buda Gavril
  • 21,409
  • 40
  • 127
  • 196
  • The *variable*? assuming the type here is a reference-type - the variable will take exactly 4 or 8 bytes... You should replace "variable" with "object" (presumably) throughout. – Marc Gravell Feb 16 '15 at 13:11
  • 1
    This sounds like an [XY problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem)... what are you trying to achieve? – Sayse Feb 16 '15 at 13:12
  • @Sayse: "Is there other way to get the memory needed by a object?" I need to know how much memory occupies an object – Buda Gavril Feb 16 '15 at 13:15
  • 2
    @BudaGavril - For the majority of things you do in c# it shouldn't matter and you should just let it handle that itself. – Sayse Feb 16 '15 at 13:22
  • For arrays and lists you can make an estimated calculation, for everything else you don't need to know. – H H Feb 16 '15 at 13:26
  • The dupe lists five more question on this topic. – H H Feb 16 '15 at 13:27
  • Indeed, the question that you've linked has an answer, but it's not marked as accepted. And for the arrays and lists, I cannot use estimated calculation because I have table variables (I use EF 1) and some records can have related table objects, some not... I cannot use third party tools(company policy) – Buda Gavril Feb 16 '15 at 13:45
  • So which 'object' did you want to measure? The EF object chache? – H H Feb 16 '15 at 13:53
  • And really, Entity Framework 1? That was more of a joke... – H H Feb 16 '15 at 13:54
  • yeah, sorry, it was EF 3.5 and I want to know the size in bytes of an array of a custom type and the type has some table members among other strings and int's. – Buda Gavril Feb 16 '15 at 14:03
  • 1
    So it's not a single object but a (very complex) cluster. Still sounds like an XY problem. To convince us therwise, specify _why_ you need this. – H H Feb 16 '15 at 14:13

0 Answers0