Size of an Object

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there any way to get the memory size for an instance of an object, like in
bytes or something like that. I have an UNDO feature on one of my
applications and I'd like to be able to display a warning when the UNDO que
got to a certain size. I can't use UndoQue.Count since the objects in the
que can vary from strings to DataTable Rows to other large objects.
 
Norman said:
Marshal.SizeOf

That won't help you. Marshal.SizeOf does NOT return the size of a
managed object. It returns the size the object will be when marshaled
to unmanaged memory. It's return value will almost certainly be
different then the actual size of the object in managed memory.
 
Dennis said:
Is there any way to get the memory size for an instance of an object, like in
bytes or something like that. I have an UNDO feature on one of my
applications and I'd like to be able to display a warning when the UNDO que
got to a certain size. I can't use UndoQue.Count since the objects in the
que can vary from strings to DataTable Rows to other large objects.

Dennis -

I don't think there is a way to acurately get the size of an object in
memory - and I believe this is on purpose. As for a solution to your
problem - I'll have to think about it a little more (maybe someone else
will come up with something)...
 
Back
Top