Home All Groups Group Topic Archive Search About
Author
15 Sep 2006 12:22 AM
Dennis
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 in Houston

Author
15 Sep 2006 3:45 AM
Norman Diamond
Marshal.SizeOf


Show quoteHide quote
"Dennis" <Den***@discussions.microsoft.com> wrote in message
news:D26833B6-5CAD-41CC-B952-5B241D4420BE@microsoft.com...
> 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 in Houston
Author
15 Sep 2006 4:10 AM
Tom Shelton
Norman Diamond wrote:
> 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.

--
Tom Shelton
Author
15 Sep 2006 4:13 AM
Tom Shelton
Dennis wrote:
> 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 in Houston

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)...

--
Tom Shelton
Author
15 Sep 2006 11:43 PM
Dennis
Thanks.  If I could an approximation it would probably suffice for what I
want to do.
--
Dennis in Houston


Show quoteHide quote
"Tom Shelton" wrote:

>
> Dennis wrote:
> > 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 in Houston
>
> 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)...
>
> --
> Tom Shelton
>
>