Solved

Memory Allocation with multiple instances of a Class

Posted on 2008-06-20
3
403 Views
Last Modified: 2013-12-17
Hi, Experts -
I have a question born more of curiousity than criticallty. Let's say that I create a class "Widget". In this class is a set of functions and routines necessary to process Widget. I then have a program that creates 1000 instances of Widget into a Collection of Widgets.

Does VB.NET allocate memory and run a full 1000 duplicates of the code? I assume that they run in the same process space as the program that created the collection, since they are not on different threads. Or does the code for the functions/routines somehow get shared by all 1000 instances of Widget?

Many thanks for your clarification!

LongDave
0
Comment
Question by:LongDave
  • 2
3 Comments
 
LVL 41

Expert Comment

by:graye
ID: 21833117
Yes, they are all created separately and run in the same process space.   There *is* a way you can write a class that uses the "Shared" keyword... this allows you to actually have (at least a part) of the class instances that are shared amoung the 1000 copies.   However, the usefulness of the Shared keyword may not be that great depending on what your class does.
0
 
LVL 41

Accepted Solution

by:
graye earned 125 total points
ID: 21833122
0
 

Author Closing Comment

by:LongDave
ID: 31469234
Thanks, bud - points to you.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A list of useful business intelligence software.
In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question