Re: How do you figure out how much memory a class is using?
From: Jay B. Harlow [MVP - Outlook] (Jay_Harlow_MVP_at_msn.com)
Date: 04/29/04
- Next message: CJ Taylor: "Re: I wish"
- Previous message: Robin Tucker: "Re: Problem with auto-indent, auto-complete, intellisense...."
- In reply to: Joe Fallon: "Re: How do you figure out how much memory a class is using?"
- Next in thread: Joe Fallon: "Re: How do you figure out how much memory a class is using?"
- Reply: Joe Fallon: "Re: How do you figure out how much memory a class is using?"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 29 Apr 2004 07:32:26 -0500
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
> > >
> > >
> > >
> > >
> >
> >
>
>
- Next message: CJ Taylor: "Re: I wish"
- Previous message: Robin Tucker: "Re: Problem with auto-indent, auto-complete, intellisense...."
- In reply to: Joe Fallon: "Re: How do you figure out how much memory a class is using?"
- Next in thread: Joe Fallon: "Re: How do you figure out how much memory a class is using?"
- Reply: Joe Fallon: "Re: How do you figure out how much memory a class is using?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|