473,387 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Objectlists and memory

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
2 1140
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Andreas Suurkuusk | last post by:
Hi, I just noticed your post in the "C# memory problem: no end for our problem?" thread. In the post you implied that I do not how the garbage collector works and that I mislead people. Since...
22
by: xixi | last post by:
hi, we are using db2 udb v8.1 for windows, i have changed the buffer pool size to accommadate better performance, say size 200000, if i have multiple connection to the same database from...
5
by: kumarmdb2 | last post by:
Hi guys, For last few days we are getting out of private memory error. We have a development environment. We tried to figure out the problem but we believe that it might be related to the OS...
1
by: Jean-Paul Calderone | last post by:
On Tue, 22 Apr 2008 14:54:37 -0700 (PDT), yzghan@gmail.com wrote: The test doesn't demonstrate any leaks. It does demonstrate that memory usage can remain at or near peak memory usage even after...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.