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


Date: Thu, 29 Apr 2004 08:47:38 -0400

Jay,
That is very interesting.
Session, Viewstate, Cache, Application,

Can you elaborate on how you control these with some sample code?

I am sure it is not an "all or nothing" solution. You must be able to
control a given variable (like my large collection) using any one of
Session, Viewstate, Cache, Application. I would like to see how you do it so
I don't go down the wrong path again!

Thanks for another good idea!

-- 
Joe Fallon
"Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in message
news:uRivVYeLEHA.2716@tk2msftngp13.phx.gbl...
> Joe,
> > 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.
> I hope you encapsulated your If in a property in a well known place.
>
> In fact I normally encapsulate all access to Session, Viewstate, Cache,
> Application, & etc variables in properties in a well known place. This
> allows a "single" point of change if I decide that Cache is better then
> Session for the variable...
>
> This well known place could either be a shared property of a domain class
> (causes coupling to ASP.NET) or a base Page or Control class in ASP.NET. I
> normally go for the base Page or Control class, although the domain class
> makes its easier (the property is in a single place, verses two places).
> Note there are ways to mitigate the coupling to ASP.NET if you choose to
put
> the property in the domain class...
>
> Hope this helps
> Jay
>
>
>
> "Joe Fallon" <jfallon1@nospamtwcny.rr.com> wrote in message
> news:uUKCEeZLEHA.628@TK2MSFTNGP11.phx.gbl...
> > 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
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>


Relevant Pages

  • Re: Session Madness
    ... Well Kevin, whatever the truth behind the problem, your suggestion saved the ... > has something to do with why the Control is not being rendered as ... that it is not a good idea to store UI elements in Session. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: IE hosted .NET control as webservice client
    ... The hosted controls know nothing about the session.To the best of my ... You could probably specify the session ID as one ... of the parameters within the tag so the control will then be able ... > I'v got a web aplication (many aspx and html pages), ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: IE hosted .NET control as webservice client
    ... The hosted controls know nothing about the session.To the best of my ... You could probably specify the session ID as one ... of the parameters within the tag so the control will then be able ... > I'v got a web aplication (many aspx and html pages), ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: How do you figure out how much memory a class is using?
    ... When the flag is False then I use Session to store the collection. ... I will serialize the collection to disk instead. ... > any overhead in the management of the collection... ... > "Joe Fallon" wrote in message ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Beginner question re postback
    ... Session is extremely useful and user specific. ... Querystring is great for passing small pieces of info in the URL like a PK ... Cache can be set with priorities and expirations. ... > "Joe Fallon" wrote in message ...
    (microsoft.public.dotnet.framework.aspnet)