Managing multiple instances



Hello all,
I'm working on an application where a number of what I will call core
objects are maintained within a single data structure. Each class that
must persist for the lifetime of the application inherits from the same
base class and then adds itself to a data structure of that base class
type.

When other parts of the application need to access a particular
instance of a specific object they request the object by a type
enumeration and provide the instance number of that object that is
requested. Multiple instances of the same object may be kept in the
data structure. I did not design this and don't believe in "all the
core application classes should inherit from X and they all should be
stored in the SAME data structure" but I have to work with it. So an
object is stored and retrieved according to a class identifier and the
instance number of objects with that class identifer.

So here's the rub that I'm working on now: the instance numbers of the
different objects were assigned based on the order in which the objects
were added to the data structure. So if I add three instances of class
A the first instance added would get instance identifier 1, the next
would get 2 and the last would get 3. Much of the client code within
the same application was written to request a hard coded instance
number of a class when they needed access to that instance.

As I'm sure you guessed by now changing the initialization order of the
product caused many of the instance numbers stored in the data
structure to change breaking the hard coded clients. As a first step to
improving this design I'm trying to replace the implicit assigning of
instance numbers with explicit instance numbers so changing the
initialization order will no longer break the clients.

And finally the issue I ran into: I have a class whose instances are
stored in this "one data structure to hold them all" (call it class A),
however this class is created within another class (call it class B) of
which multiple instances are created from within another class (class
C). IOW class C contains 2 instances of B each of which contain an
instance of A. So when creating instances of class A I cannot provide a
simple enumeration of the instance number when adding to the data
structure or the instance numbers will not be unique.

I'm thinking this data structure design is falling apart rapidly but
its so deeply integrated into the product redesigning it may not be
feasible right now. But I'm really stuck on how to create unique
instance numbers (that can then be referenced from within client code)
when the objects to be added to the data structure are created from
within objects that may also have multiple instances.

Thanks for reading this far. Any suggestions?

Thanks in advance,

Ben

.



Relevant Pages

  • Re: What does it mean to set large fields to null
    ... enough memory to load the graphic data into memory, ... It works hand-in-hand with the finalizer to provide client code with a well-defined API for ensuring that resources .NET has no way to explicitly manage are still released in a timely way when the client code is done with them, and a back-up system in case the client code has a bug and fails to release those resources explicitly. ... Even if you did have a data structure that could potentially allocate a large amount of memory and then later have a sensible use case where you would want to release that memory without releasing the entire data structure at all, I don't really feel that IDisposable is the right way to go about it. ... I agree with the design found, for example, in the Listclass where there's an explicit method specific to the type to accomplish that " method). ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Managing multiple instances
    ... objects are maintained within a single data structure. ... base class and then adds itself to a data structure of that base class ... instance numbers (that can then be referenced from within client code) ... If you can Ada 95 you could take a look at persistence implementation at my ...
    (comp.object)
  • [13/13] Fix powernow oops on dual-core athlon
    ... -stable review patch. ... powernow-k8 requires that a data structure for ... _cpu_init for the second core in each processor. ...
    (Linux-Kernel)
  • Re: Van Jacobsons net channels and real-time
    ... you are receiving or sending a lot. ... Cacheline bouncing is the core issue being addressed by this ... data structure, so we really can't consider your idea seriously. ...
    (Linux-Kernel)