T
ThatsIT.net.au
I was wondering about performance implications for 2 ways of creating a
collection of objects.
Lets say I have 2 classes category and subcategory
in the category class I have a function that returns a collection of
subcategory objects.
what I do here is open a reader to a table in the database with the
subcategory info in it.
I then call the subcategory class each loop of the reader creating an array
of objects like so
myarray(n) = new subcategory(id,name,other,other,other...)
as you can see am passing all the data from the database table to the class
so that no trip to the database is needed from the subcategory class all
data is supplied.
Now I know that this second way is not as efficient as it make many trips to
the database like this
myarray(n) = new subcategory(id)
passing the id only I then have to load the other data from the database
each time a subcategory object is created.
Now I know that this is a performance cost but how much of a coast I don't
know. some times these second way is a real time saver where there is much
data to pass across. since in the second way you are only getting one row
from the database each time the amount of data retrieved from the database
is the same but there is many connections to the database the second way.
Should I worry too much about this overhead?
collection of objects.
Lets say I have 2 classes category and subcategory
in the category class I have a function that returns a collection of
subcategory objects.
what I do here is open a reader to a table in the database with the
subcategory info in it.
I then call the subcategory class each loop of the reader creating an array
of objects like so
myarray(n) = new subcategory(id,name,other,other,other...)
as you can see am passing all the data from the database table to the class
so that no trip to the database is needed from the subcategory class all
data is supplied.
Now I know that this second way is not as efficient as it make many trips to
the database like this
myarray(n) = new subcategory(id)
passing the id only I then have to load the other data from the database
each time a subcategory object is created.
Now I know that this is a performance cost but how much of a coast I don't
know. some times these second way is a real time saver where there is much
data to pass across. since in the second way you are only getting one row
from the database each time the amount of data retrieved from the database
is the same but there is many connections to the database the second way.
Should I worry too much about this overhead?