Solved

Memory Allocation with multiple instances of a Class

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Add a task in Outlook from access 11 35
Windows 10 powershell/cmd/bash alternatives? 11 44
Passing a Text Box name to a Sub 6 80
how to know if my Checkbox is True in VB6.0? 9 41
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

863 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

21 Experts available now in Live!

Get 1:1 Help Now