Re: How do you figure out how much memory a class is using?
From: Joe Fallon (jfallon1_at_nospamtwcny.rr.com)
Date: 04/29/04
- Next message: Lisa Jones: "Re: I wish I could store and retrieve Sound to and from database."
- Previous message: Ken Tucker [MVP]: "Re: VB.Net Compiling problem"
- In reply to: Jay B. Harlow [MVP - Outlook]: "Re: How do you figure out how much memory a class is using?"
- Next in thread: Jay B. Harlow [MVP - Outlook]: "Re: How do you figure out how much memory a class is using?"
- Reply: Jay B. Harlow [MVP - Outlook]: "Re: How do you figure out how much memory a class is using?"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 28 Apr 2004 23:10:23 -0400
Jay,
It helps a lot.
I tried System.Runtime.InteropServices.Marshal.SizeOf on one of my classes
and it failed.
Now that I know it is basically "impossible" I can stop going down that
path.
I decided to use a web.config appsetting flag for this.
When the flag is False then I use Session to store the collection.
When it is True, I will serialize the collection to disk instead.
I only plan to do this for potentially large objects.
Smaller ones will be tossed into Session or Viewstate.
So instead of the normal 2 lines of code (1 to put the object into Session
and 1 to take it out)
I just wrap them in an If statement and check the flag.
So by default, we will store things in Session, but in a pinch can move
large objects to disk and back.
I guess that is a workable approach.
(My original goal was to dynamically test the size of the object and if it
crossed a threshold to move it to disk.)
Thanks for the help Jay!
-- Joe Fallon Access MVP "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in message news:uXAAVjYLEHA.2692@tk2msftngp13.phx.gbl... > Joe, > There is no way to get the size of a managed object per se. > > You could use System.Runtime.InteropServices.Marshal.SizeOf, however this > returns the size of the object when it is marshaled to the unmanaged world, > it does not report the true size of the object in the managed realm. > > Also I do not believe the Marshal.SizeOf method takes into account > collection classes, you could use the enumerator of the class to get the > size of each element, unfortunately this will not give you a good idea of > any overhead in the management of the collection... > > Hope this helps > Jay > > "Joe Fallon" <jfallon1@nospamtwcny.rr.com> wrote in message > news:OFEVVETLEHA.3548@TK2MSFTNGP10.phx.gbl... > > I would like to know how you can figure out how much memory a given > instance > > of a class is using. > > > > For example, if I load a collection class with 10 items it might use 1KB, > > and if I load it with 1000 items it might use 100KB. > > How do I measure the amount of memory used once the class is loaded? > > > > Thanks! > > -- > > Joe Fallon > > > > > > > > > >
- Next message: Lisa Jones: "Re: I wish I could store and retrieve Sound to and from database."
- Previous message: Ken Tucker [MVP]: "Re: VB.Net Compiling problem"
- In reply to: Jay B. Harlow [MVP - Outlook]: "Re: How do you figure out how much memory a class is using?"
- Next in thread: Jay B. Harlow [MVP - Outlook]: "Re: How do you figure out how much memory a class is using?"
- Reply: Jay B. Harlow [MVP - Outlook]: "Re: How do you figure out how much memory a class is using?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|