A common misconception for people new to oop is that the code in a class
takes up space in the memory on a per-instance basis. This is not correct.
When a class is instantiated a structure containing its internal fields and
a list of adresses for it's virtual or overridable methods is created. If a
class has say one integer field and no virtual methods the class will occupy
about four bytes of heap space even if the methods of the class require a
million lines of code to manipulate that integer. Each instance of the class
shares the physical bytes of code in memory with all the others and the
instance of the *data* for each class is referenced through the "Me"
reference ("this" in C#)
A rough example will be that Class A has 1024 bytes of code for it's methods
plus say 100 bytes for its fields, virtual method table and Me reference.
The code for A is already loaded because its program, not data but you can
consider that it takes 1124 bytes of physical memory for one instance. Two
instances however are 1224 bytes and three instances are 1324 bytes.
I hope this explanation answers your question.
--
Bob Powell [MVP]
Visual C#, System.Drawing
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
"john andrew" <jo********@discussions.microsoft.com> wrote in message
news:5F**********************************@microsof t.com...
--
hello
If I inherit an object say Car() with my new class SportsCar(). Does
vb.net creates space in memory for the object SportsCar() and associated space
for Car().
So in effect you are creating space for 2 Objects with all its
properties/methods.
If you only ever use say half the inherited class -methods/properties, are
you actually being inefficient with memory space. With the trade off being
a more OOP design....
Is the use of Inheritance a possible overhead with system space. As in the
case above.
thanks