473,386 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Penalty for instantiating an object tens of thousands of times?

What are the ramifications if I were to instantiate an object tens of
thousands of times and add them to an array? Or hundreds of thousands of
times? Do you know if the act of instantiating a class takes a lot of
storage or other resources? Would it be a severe performance penalty?

From the .Net help doc:

You declare and use arrays of an object type just as you would declare and
use an array of any data type. The members of this array can be retrieved by
their index, and can be manipulated as any object of this type would be.
Arrays also have built-in functionality for searching and sorting that can
be accessed through the array variable. For more information on these
methods, see Array Class.

To create an array of objects

Declare the array as shown in the sample code below. Because arrays are
zero-based, they contain one member more than the upper bound you declare.

Dim x(10) As Widget ' Contains 11 members, from x(0) to x(10).

Instantiate each member of the array, or assign each member a reference to
an already existing object. An example of each approach is shown below:

' Instantiates each member of an array by using a loop.

Dim q As Integer

For q = 0 to 10

x(q) = New Widget()

Next

' Assigns a member of an array a reference to an existing object.

Dim myWidget As New Widget()

x(0) = myWidget

x(1) = myWidget

Note that you can assign the different members of the array references to
the same object.
Nov 21 '05 #1
6 1608
Dont forget you are storing references to these objects in the array. The
main penalty is use of memory but if there is enough of it then you should
be ok. I suppose it might give the Garbage collector something to chew on.
I would suggest you write a loop to generate it and see what happens.
--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
"Gary Frank" <ga**************@REMOVEsbcglobal.net> wrote in message
news:bD*****************@newssvr11.news.prodigy.co m...
What are the ramifications if I were to instantiate an object tens of
thousands of times and add them to an array? Or hundreds of thousands of
times? Do you know if the act of instantiating a class takes a lot of
storage or other resources? Would it be a severe performance penalty?

From the .Net help doc:

You declare and use arrays of an object type just as you would declare and
use an array of any data type. The members of this array can be retrieved
by their index, and can be manipulated as any object of this type would
be. Arrays also have built-in functionality for searching and sorting that
can be accessed through the array variable. For more information on these
methods, see Array Class.

To create an array of objects

Declare the array as shown in the sample code below. Because arrays are
zero-based, they contain one member more than the upper bound you declare.

Dim x(10) As Widget ' Contains 11 members, from x(0) to x(10).

Instantiate each member of the array, or assign each member a reference to
an already existing object. An example of each approach is shown below:

' Instantiates each member of an array by using a loop.

Dim q As Integer

For q = 0 to 10

x(q) = New Widget()

Next

' Assigns a member of an array a reference to an existing object.

Dim myWidget As New Widget()

x(0) = myWidget

x(1) = myWidget

Note that you can assign the different members of the array references to
the same object.

Nov 21 '05 #2
Nak
Hi there,

I wouldn't worry if I were you, I made a 3D engine which opened obj
files, this instantiated thousands upon thousands of objects. The only
speed pentalty was drawing them using GDI+. But one thing you might find
benificial is making typed collections, this way you can have the benefit of
a collection object rather that having to handle arrays on your own.

You can check out my 3D engine, it's not amazing trust me, but it is
capabale of creating allot of objects!

http://www.members.lycos.co.uk/nickpatemanpwp/

Go to "My own software > Starfield +", you'll notice that the engine is
called crapEngine, but it isn't that bad honest! :-)

Nick.

"Gary Frank" <ga**************@REMOVEsbcglobal.net> wrote in message
news:bD*****************@newssvr11.news.prodigy.co m...
What are the ramifications if I were to instantiate an object tens of
thousands of times and add them to an array? Or hundreds of thousands of
times? Do you know if the act of instantiating a class takes a lot of
storage or other resources? Would it be a severe performance penalty?

From the .Net help doc:

You declare and use arrays of an object type just as you would declare and
use an array of any data type. The members of this array can be retrieved
by their index, and can be manipulated as any object of this type would
be. Arrays also have built-in functionality for searching and sorting that
can be accessed through the array variable. For more information on these
methods, see Array Class.

To create an array of objects

Declare the array as shown in the sample code below. Because arrays are
zero-based, they contain one member more than the upper bound you declare.

Dim x(10) As Widget ' Contains 11 members, from x(0) to x(10).

Instantiate each member of the array, or assign each member a reference to
an already existing object. An example of each approach is shown below:

' Instantiates each member of an array by using a loop.

Dim q As Integer

For q = 0 to 10

x(q) = New Widget()

Next

' Assigns a member of an array a reference to an existing object.

Dim myWidget As New Widget()

x(0) = myWidget

x(1) = myWidget

Note that you can assign the different members of the array references to
the same object.

Nov 21 '05 #3
Clever spam filter!

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:Os**************@TK2MSFTNGP15.phx.gbl...
Dont forget you are storing references to these objects in the array. The
main penalty is use of memory but if there is enough of it then you should
be ok. I suppose it might give the Garbage collector something to chew
on. I would suggest you write a loop to generate it and see what happens.
--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
"Gary Frank" <ga**************@REMOVEsbcglobal.net> wrote in message
news:bD*****************@newssvr11.news.prodigy.co m...
What are the ramifications if I were to instantiate an object tens of
thousands of times and add them to an array? Or hundreds of thousands of
times? Do you know if the act of instantiating a class takes a lot of
storage or other resources? Would it be a severe performance penalty?

From the .Net help doc:

You declare and use arrays of an object type just as you would declare
and use an array of any data type. The members of this array can be
retrieved by their index, and can be manipulated as any object of this
type would be. Arrays also have built-in functionality for searching and
sorting that can be accessed through the array variable. For more
information on these methods, see Array Class.

To create an array of objects

Declare the array as shown in the sample code below. Because arrays are
zero-based, they contain one member more than the upper bound you
declare.

Dim x(10) As Widget ' Contains 11 members, from x(0) to x(10).

Instantiate each member of the array, or assign each member a reference
to an already existing object. An example of each approach is shown
below:

' Instantiates each member of an array by using a loop.

Dim q As Integer

For q = 0 to 10

x(q) = New Widget()

Next

' Assigns a member of an array a reference to an existing object.

Dim myWidget As New Widget()

x(0) = myWidget

x(1) = myWidget

Note that you can assign the different members of the array references to
the same object.


Nov 21 '05 #4
I read you note and was curious as to how to make a typed collection? Do you
have any code examples or references?

"Nak" wrote:
Hi there,

I wouldn't worry if I were you, I made a 3D engine which opened obj
files, this instantiated thousands upon thousands of objects. The only
speed pentalty was drawing them using GDI+. But one thing you might find
benificial is making typed collections, this way you can have the benefit of
a collection object rather that having to handle arrays on your own.

You can check out my 3D engine, it's not amazing trust me, but it is
capabale of creating allot of objects!

http://www.members.lycos.co.uk/nickpatemanpwp/

Go to "My own software > Starfield +", you'll notice that the engine is
called crapEngine, but it isn't that bad honest! :-)

Nick.

"Gary Frank" <ga**************@REMOVEsbcglobal.net> wrote in message
news:bD*****************@newssvr11.news.prodigy.co m...
What are the ramifications if I were to instantiate an object tens of
thousands of times and add them to an array? Or hundreds of thousands of
times? Do you know if the act of instantiating a class takes a lot of
storage or other resources? Would it be a severe performance penalty?

From the .Net help doc:

You declare and use arrays of an object type just as you would declare and
use an array of any data type. The members of this array can be retrieved
by their index, and can be manipulated as any object of this type would
be. Arrays also have built-in functionality for searching and sorting that
can be accessed through the array variable. For more information on these
methods, see Array Class.

To create an array of objects

Declare the array as shown in the sample code below. Because arrays are
zero-based, they contain one member more than the upper bound you declare.

Dim x(10) As Widget ' Contains 11 members, from x(0) to x(10).

Instantiate each member of the array, or assign each member a reference to
an already existing object. An example of each approach is shown below:

' Instantiates each member of an array by using a loop.

Dim q As Integer

For q = 0 to 10

x(q) = New Widget()

Next

' Assigns a member of an array a reference to an existing object.

Dim myWidget As New Widget()

x(0) = myWidget

x(1) = myWidget

Note that you can assign the different members of the array references to
the same object.


Nov 21 '05 #5

"Gary Frank" <ga**************@REMOVEsbcglobal.net> wrote
What are the ramifications if I were to instantiate an object tens of
thousands of times and add them to an array? Or hundreds of thousands of
times? Do you know if the act of instantiating a class takes a lot of
storage or other resources? Would it be a severe performance penalty?


Creating new objects require memory, where the amount required depends
on the size of the object you are creating.. Under normal conditions the CLR
(runtime) is looking right at a large free memory area so allocations go real
quick, until you run out of memory.

HTH
LFS

Nov 21 '05 #6
:)

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
"Jared" <as***********@nospam.com> wrote in message
news:10*************@corp.supernews.com...
Clever spam filter!

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in
message news:Os**************@TK2MSFTNGP15.phx.gbl...
Dont forget you are storing references to these objects in the array. The
main penalty is use of memory but if there is enough of it then you
should be ok. I suppose it might give the Garbage collector something to
chew on. I would suggest you write a loop to generate it and see what
happens.
--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
"Gary Frank" <ga**************@REMOVEsbcglobal.net> wrote in message
news:bD*****************@newssvr11.news.prodigy.co m...
What are the ramifications if I were to instantiate an object tens of
thousands of times and add them to an array? Or hundreds of thousands
of times? Do you know if the act of instantiating a class takes a lot
of storage or other resources? Would it be a severe performance
penalty?

From the .Net help doc:

You declare and use arrays of an object type just as you would declare
and use an array of any data type. The members of this array can be
retrieved by their index, and can be manipulated as any object of this
type would be. Arrays also have built-in functionality for searching and
sorting that can be accessed through the array variable. For more
information on these methods, see Array Class.

To create an array of objects

Declare the array as shown in the sample code below. Because arrays are
zero-based, they contain one member more than the upper bound you
declare.

Dim x(10) As Widget ' Contains 11 members, from x(0) to x(10).

Instantiate each member of the array, or assign each member a reference
to an already existing object. An example of each approach is shown
below:

' Instantiates each member of an array by using a loop.

Dim q As Integer

For q = 0 to 10

x(q) = New Widget()

Next

' Assigns a member of an array a reference to an existing object.

Dim myWidget As New Widget()

x(0) = myWidget

x(1) = myWidget

Note that you can assign the different members of the array references
to the same object.



Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Roberto Gerola | last post by:
Hi, I've developed for our PHP projects a little object persistence library. Tha main goal of the library is to speed up the management of the data stored in a db. It is based on the concept...
1
by: Peter Bär | last post by:
A Question to the C#/.Net Gods of this forum: are there performance penalties when i compile (C#, FW1.1, ASP.NET, Studio2003) a central baseclass in a different assembly than all the derived...
2
by: Peter Bär | last post by:
A Question to the C#/.Net Gods of this forum: are there performance penalties when i compile (C#, FW1.1, ASP.NET, Studio2003) a central baseclass in a different assembly than all the derived...
2
by: HarishP | last post by:
Hi, How to avoid instantiating the class more than 10 times Harish.P Sr. Software Engineer Comat Technologies Pvt. Ltd., Bangalore Email: harish.p@comat.com
5
by: Chris Spencer | last post by:
Before I get too carried away with something that's probably unnecessary, please allow me to throw around some ideas. I've been looking for a method of transparent, scalable, and human-readable...
2
by: Kevin Stone | last post by:
Hi, I currently have a piece of JavaScript which swaps the on-screen image between two different versions, and I use: document.images.src = something and change the src each time. However,...
36
by: zouyongbin | last post by:
Stanley B Lippman in his "C++ Primer" that a definition like this should not appear in a header file: int ix; The inclusion of any of these definitions in two or more files of the same...
3
by: Berteun Damman | last post by:
Hello, I have programmed some python script that loads a graph (the mathemical one with vertices and edges) into memory, does some transformations on it, and then tries to find shortest paths in...
2
by: Aaron Watters | last post by:
Poking around I discovered somewhere someone saying that Python gc adds a 4-7% speed penalty. So since I was pretty sure I was not creating reference cycles in nucular I tried running the tests...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.