Discussion:
would List<> be the best container?
(too old to reply)
mp
2016-12-12 21:21:20 UTC
Permalink
Hi,
If I have an object cBuilding which is a collection of all
cBuildingComponent objects, would List<cBuildingComponent> be the most
efficient storage container?

my assumption is the components would not be stored by name, just added
to collection by index

my thought is the cBuilding object will contain all created objects with
their data etc, then be used to serialize and deserialize on open/close
project.

pseudocode
foreach object in objects
object.serialize filename
-or-
objects.deserialize filename

is that the right idea?

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
Marcel Mueller
2016-12-12 23:15:16 UTC
Permalink
Post by mp
Hi,
If I have an object cBuilding which is a collection of all
cBuildingComponent objects, would List<cBuildingComponent> be the most
efficient storage container?
Efficient with respect to what?

Memory consumption? - no, cBuildingComponent[] is smaller
Lines of code? - maybe, List<> is easy to use
Changes? - probably not, since List<> needs to copy elements at
insertion or removal in the middle.
Other criterion?
Post by mp
my assumption is the components would not be stored by name, just added
to collection by index
True. List<T> is a wrapper around T[] to automatically adjust the array
size to fit the needs. In many cases it is a good choice. No more, no less.
Post by mp
my thought is the cBuilding object will contain all created objects with
their data etc, then be used to serialize and deserialize on open/close
project.
List<T> is just fine for this purpose unless we are talking about more
than several thousand objects.
Post by mp
pseudocode
foreach object in objects
object.serialize filename
-or-
objects.deserialize filename
is that the right idea?
Serialize/deserialize needs to be symmetric. I.e.

objects.serialize filename
...
objects.deserialize filename


Marcel
mp
2016-12-13 12:34:46 UTC
Permalink
Post by Marcel Mueller
Post by mp
Hi,
If I have an object cBuilding which is a collection of all
cBuildingComponent objects, would List<cBuildingComponent> be the most
efficient storage container?
Efficient with respect to what?
thank you Marcel, I hadn't thought of all those considerations
i was naively thinking of end user experience, eg which type would be
fastest in operation, wanting to avoid using something that would slow a
program execution. (not sure if that would be same as memory consumption
or processor workload or something - as you can tell i'm not very
computer savvy :-) )
Post by Marcel Mueller
Memory consumption? - no, cBuildingComponent[] is smaller
Lines of code? - maybe, List<> is easy to use
easy on user hard on developer is fine with me ;-)
Post by Marcel Mueller
Changes? - probably not, since List<> needs to copy elements at
insertion or removal in the middle.
Other criterion?
List<T> is just fine for this purpose unless we are talking about more
than several thousand objects.
another good question...i could imagine it holding hundreds up to a few
thousand but not likely 100,000 or millions ... but assuming I don't
want to limit possible use case, what would I use if List<T> became too
restrictive?
I assume array[T] ???
Post by Marcel Mueller
Serialize/deserialize needs to be symmetric. I.e.
objects.serialize filename
...
objects.deserialize filename
Marcel
thank you



---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
Arne Vajhøj
2016-12-13 00:54:40 UTC
Permalink
Post by mp
If I have an object cBuilding which is a collection of all
cBuildingComponent objects, would List<cBuildingComponent> be the most
efficient storage container?
my assumption is the components would not be stored by name, just added
to collection by index
my thought is the cBuilding object will contain all created objects with
their data etc, then be used to serialize and deserialize on open/close
project.
Impossible to say fir sure with so little information.

But List<> is a good starting point, so start with that and
see if you find a good reason to change it later.
Post by mp
pseudocode
foreach object in objects
object.serialize filename
-or-
objects.deserialize filename
is that the right idea?
If you use .NET builtin serialization then you can serialize and
deserialize the entire list at once, so you do not even need a loop.

Arne
mp
2016-12-13 12:52:05 UTC
Permalink
Post by Arne Vajhøj
Post by mp
If I have an object cBuilding which is a collection of all
cBuildingComponent objects, would List<cBuildingComponent> be the most
efficient storage container?
my assumption is the components would not be stored by name, just added
to collection by index
my thought is the cBuilding object will contain all created objects with
their data etc, then be used to serialize and deserialize on open/close
project.
Impossible to say fir sure with so little information.
But List<> is a good starting point, so start with that and
see if you find a good reason to change it later.
Post by mp
pseudocode
foreach object in objects
object.serialize filename
-or-
objects.deserialize filename
is that the right idea?
If you use .NET builtin serialization then you can serialize and
deserialize the entire list at once, so you do not even need a loop.
Arne
thank you Arne
at this point i'm creating all the classes i can think of and everything
is basically blank stubs for now, but want to write such that as (if) it
develops further it will be easiest to modify as I discover problems
with my first ideas. In that context not sure how best to hide
implementation of the List<T> such that if that needs to change later to
use some other kind of storage there would be least amount of code to change

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

Continue reading on narkive:
Loading...