Re: Object creation overhead

From: nos (nos_at_nospam.com)
Date: 11/27/03


Date: Thu, 27 Nov 2003 05:23:19 GMT

ya, very helpful, thanks for taking the time to explain

"Anthony Borla" <ajborla@bigpond.com> wrote in message
news:x0cxb.28557$aT.9305@news-server.bigpond.net.au...
>
> "nos" <nos@nospam.com> wrote in message
> news:shbxb.316149$Tr4.986273@attbi_s03...
> >
> > please, what is a "proxy" object? how to make one?
> >
>
> It's just a plain object that is used to represent or take the place of
> another object. While useful in many situations [i.e. there can be many
> reasons for using proxies including security reasons, and minimising
> resources loadtimes etc], one particular use is to reduce the memory
> footprint of a Collection-type of data structure.
>
> For example, you need to have an 'ArrayList' object manage 1000 objects of
> 'MyClass'; this class looks like:
>
> class MyClass
> {
> ...
> // Lots of fields ...
> private long id;
> private String name;
> private String address;
> ...
> }
>
> If 'MyClass' has twenty 'String' fields then that means that memory for
> 20,000 'String' objects is needed, both to manage them, and for the
'String'
> data. This is, of course, over and above the memory required for the
> 'MyClass' objects themselves.
>
> The 'proxy' class approach won't see a reduction in the number of
'MyClass'
> objects, merely a reduction in the amount of memory each may require for
its
> field data. So, the original class is now split into two; there is the
proxy
> class:
>
> class MyClassProxy
> {
> ...
> // Only a couple of fields needed...
> private long id;
> ...
> // Method to retrieve the actual object proxied by this one
> public MyClass getMyClassObject() { ... }
> ...
> }
>
> and a modified, probably pared-down, version of the original class:
>
> class MyClass
> {
> ...
> // Still lots of fields, but probably less methods ...
> private long id;
> private String name;
> private String address;
> ...
> }
>
> With the 'ArrayList' object loaded with 'MyClassProxy' objects, less
memory
> is being used. Only when a 'MyClassProxy' object is selected is a
'MyClass'
> object instantiated, using data stored somewhere else *outside memory*
[e.g.
> file, database, URL, etc].
>
> Note:
>
> * This approach has many variants - I have provided a very simple
> example, and ignored / glossed over the implementation issues.
> However the general approach is:
>
> - Use proxy object in place of real object
>
> - When proxy object is selected have it retrieve / create
> the real object
>
> * Proxy cannot [usually] be used where access / retrieval time is
> crucial
>
> More substantial examples, and relevant in-depth discussions may be found
by
> Google searching for 'Proxy Design Pattern'.
>
> I hope this helps.
>
> Anthony Borla
>
>



Relevant Pages

  • Re: Object creation overhead
    ... one particular use is to reduce the memory ... 'MyClass'; this class looks like: ... 20,000 'String' objects is needed, both to manage them, and for the 'String' ... The 'proxy' class approach won't see a reduction in the number of 'MyClass' ...
    (comp.lang.java)
  • Expenses For Allocating New Objects
    ... class MyClass { ... When you create a new instance of MyClass, I know new memory is ... allocated for mOnlyMember, but is new memory also allocated for ...
    (comp.lang.java.programmer)
  • Re: Passing User Define class to web service.
    ... First, you should try to update your web reference, then go to the generated ... that when the new web service proxy is ... >> likely problem is that myClass is multiply defined in separate namespaces ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • Re: Is it good programming to set instance in class without using C-tor
    ... I have a class definition called MyClass see below. ... I create an instance of this class MyClass ... the question of what arguments should go on the constructor is ... your client has to test before they try to use an object instance. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: C# confusion
    ... If you create instances of MyClass, ... you are allocating an area of memory for the data segment for each ... data members are initialised upon first reference of the class. ... static keyword; This one has been hitting me like a hammer on the ...
    (microsoft.public.dotnet.languages.csharp)