Link to home
Start Free TrialLog in
Avatar of GPrentice00

asked on

Generic java OOP/ memory-resource concept

I have a feeling that I know the answer is 'its not more intense' to the following question, but I wanna be sure :)

I need to set up 3 example classes to outline the question.  I dont want the first comment to be "make C inherit A" or such, because thats not the purpose of the question.

Presume I want to make a class to model a single particle object in a system, and have some complex math to act on a single particle.  And that I'm going to want to throw more particles in at some point..  This is pure example, I am not modelling particles.  Substitude tic-tac-toe diagrams, me playing god and designing animals from scratch, etc, etc - im using a particle to represent my understanding of OOPs, I could have used animals or vehicles or such as well...  I am actually coding minecraft server plugins, and wanting to expand my complexity in them.

Class ParticleA : Has 4 integer values, 4 floats, a string name, and a two longs.  Also has the getters and setters for each parameter, with one constructor.

Class ParticleB: Same as class A with the data, the individual getter/setters , and constructor; but has 5 methods that do complex mathematics using most of the values within the object to return values based on the internal data, and one to change various parameters in the object based on a void method call with inputs.

Class ParticleC: Same as class A, with the same data, individual getter/setters, and constructor;  but has 50 methods that do complex mathematics on the particle data to return values, and 10 void methods to change the data from inputs.

At some point, I then want to make an array of particles, lets say 100.  So I naturally would make an array of whichever class I would be using.

In all cases, the internal data structure for each object is the same, so an array of 100 objects is going to be using 100 x the (4 integers, 4 floats, 1 string... ) data in terms of resources, regardless of class A B or C

Does the size and complexity of the methods involved in the B and C classes result in a substantially larger storage/resource requirement such that an array of class B is significantly bigger than of A, and that class C is massive compared to A?  

OR is the data-storage component for the object really the 99% of the storage requirments, and all the methods in it add no weight to the actual object?  

In Class B example, the methods act to evaluate and report on something frequently, properties that need to be monitored continuously or fed back, and really are oop-based concepts like "MyPosition" and "MyTemperature" for the particle.

In Class C example, say out of the 45 something new methods, most are "Myproperty" based as well, but, are also very complex equations, and barely even used 99.9% of the time, they are just there in the class definition to keep all the possible function uses together.  

Since class C has a huge overhead of 'seldom used, complex, heavy-overhead' stuff that is part of it, but, not a true necessity to keep in it the particle itself, as the rarity of the calls to them, and complexity may be better served by a single class object that is functions acting on a particle object parameter to spit out a value.  Like a TragectoryComputing object, 45 equations, one instance of the object -- simplifies the code of each particle class, indeed for that purpose later, but, at some level, has pulled logically-put-it-in-particle code out....

I'm falling off the track of my question here, I realize.   The main point for my question is with these three particle classes, and an array of each class..

How will each array compare in memory --does each instance of the class take up a, b and c amount, and an n-array thus take up na, nb and nc.   Or despite all the methods, getters and setters involved, does this contribute only one iota or two iotas of difference , making the comparison of arrays be  (na, n(a+iota), n(a + iota + few iota) ) where iota is rather small compared to the amount a required  for just the data.

On top of that, are there any other concerns - performance comparisons - between an array of particles A, B and C -- iterating through them, will each array type take longer and longer to iterate through all 100 and call 3 simple getters, or will it be virtually indistinguishable.  Speed isn't a critical issue here, but memory use is, and being effective memory storage is, with such arrays created and destroyed moments later, on and on and on and on -- needs to be garbage collection friendly
Avatar of dpearson

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GPrentice00


cool - not even an iota difference.  my money was on an iota.

So for gc purposes as well, none of these arrays would be effectively different from each other in any way, and all three would be treated the same via whatever way I handle the array in the first place. -- if 'middle group' is referring to your description of memory allocations vs lifetimes comparisons, and not "particleB"?