By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,781 Members | 1,373 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,781 IT Pros & Developers. It's quick & easy.

Objectlists and memory

P: n/a
Hi!

The basic questions here is how an object is stored in memory.

I have an list of a custom object, where the object has a couple of fields,
properties and methods. If we pretend that he fields take 24bytes, the
properties take 12bytes and the methods take 36bytes of code for this
particular object, will the lists memory consumption be (24+12+36)*number of
objects in list ?

I understand that you have to store the field data for each object, as it
probably differs, but how about properties and methods?

Especially method looks the same regardless of what object we are looking at
(I may be mistaking here), so why store the method memory for each object in
a list? Or am I talking STATIC methods here?

Why I am asking is that I am playing around with business layer objects, and
these objects don't have a lot of fields, but the code for the methods might
be quite long. So if the list of these objects is quite long it would
contain a lot of redundant code of the same method code.

Oh well, any comments are welcome :-)

/ Peter
May 11 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,

"Peter Hartlén" <pe***@data.se> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Hi!

The basic questions here is how an object is stored in memory.
Your first step should be http://www.yoda.arachsys.com/csharp/memory.html
I have an list of a custom object, where the object has a couple of
fields, properties and methods. If we pretend that he fields take 24bytes,
In any case the references takes that, unless all your fields are
primitive values types (int, char, long, etc)
If you have a reference type (string , object ) you cannot be sure how big
they are.
properties take 12bytes and the methods take 36bytes of code for this
particular object, will the lists memory consumption be (24+12+36)*number
of objects in list ?
Not at all, the code exist only once.
I understand that you have to store the field data for each object, as it
probably differs, but how about properties and methods?


They exist only once, and not in the same place than the data !

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
May 11 '06 #2

P: n/a
The size is, 1*(12+36)+n*(24+SIZEOF(Object)+system
overhead)=(code)+n*(data+parent objects data+system header data).

That is, the methods and properties (I assume you mean accessors to fields)
are shared between all the instances of the same class. Only data is
different so when you create a new MyObject the system creates only a data
container.

Laura

"Peter Hartlén" <pe***@data.se> ha scritto nel messaggio
news:%2****************@TK2MSFTNGP04.phx.gbl...
Hi!

The basic questions here is how an object is stored in memory.

I have an list of a custom object, where the object has a couple of
fields, properties and methods. If we pretend that he fields take 24bytes,
the properties take 12bytes and the methods take 36bytes of code for this
particular object, will the lists memory consumption be (24+12+36)*number
of objects in list ?

I understand that you have to store the field data for each object, as it
probably differs, but how about properties and methods?

Especially method looks the same regardless of what object we are looking
at (I may be mistaking here), so why store the method memory for each
object in a list? Or am I talking STATIC methods here?

Why I am asking is that I am playing around with business layer objects,
and these objects don't have a lot of fields, but the code for the methods
might be quite long. So if the list of these objects is quite long it
would contain a lot of redundant code of the same method code.

Oh well, any comments are welcome :-)

/ Peter

May 11 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.