Solved

Memory Allocation with multiple instances of a Class

Posted on 2008-06-20
3
399 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

I previously wrote an article addressing the use of UBCD4WIN and SARDU. All are great, but I have always been an advocate of SARDU. Recently it was suggested that I go back and take a look at Easy2Boot in comparison.
A list of useful business intelligence software.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

746 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now