vb.net and OOP (inheritance)

G

Guest

--
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
 
C

Cor Ligthert

John,

The only advice I can give you at the moment is, don't worry about this at
the moment. When you are a little bit further you learn what objects are
created and how. Now it will be only confusing and makes that you don't go
in the right direction.

However to tell something. There are as much objects created on the managed
heap as often that you tell.

Private(or whatever) John as New Andrew.

Private(or whatever) John as Andrew, creates only an empty place to set the
reference (address) to the next John you create from Andrew

When you look at the control classes , you will see that they inherrit every
time up with in the top Object.

I hope this helps?

Cor
 
G

Guest

Hi

Well I can do a fair bit with .Net already eg build classes, use controls
similiar to VB6...not everthing though but I take your point. VB.net isnt
that daunting since I have C/Java background but it will take time to be
effective in.
 
B

Bob Powell [MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top