Re: How to give selective access to the methods in a class?

Eric Sosman wrote:
toton wrote:
Eric Sosman wrote:

toton wrote On 08/09/06 10:24,:

How much
effective is this in long run? i.e will JIT make the object contains
side by side? or they will be scattered? (boils down to the question,
array holds the object itself or just the reference ? )

The instances exist "somewhere else," and the ArrayList
holds references to them. The instances might be scattered
or might be grouped together; they might even move around to
different memory locations at different times. That's the
JVM's worry, not yours: The reference still leads to the
instance, no matter where it happens to be located.

Yes, its JVM's worry. I know that. My worry is that, do JVM really
worry to keep frequently accessed objects in nearby places?

Not that I know of -- but then, I've never bothered to look.
Also, there is more than one JVM, and different JVMs have different
strategies for managing memory.

The second thing what I wanted to know, for Vector or ArrayList type of
random access container, how much effective the load factor or initial
capacity, as the container doesn't hold the object itself. One need to
choose them judicially for STL containers, whent they contains the
objects itself, otherwise frequent memory copy occures. One can see a
visable performance difference there. Is that kind of fine tuning is
necessary for JCF Vector or ArrayList, (or default value of 10 works
fine irrespective of ArrayList size? ) )as it stores the reference
only, the increase in size out of capicity will cause only copy of
reference, not the object itself.

If you happen to know roughly how many objects the list will
eventually contain, you can save some time by making the list that
large to begin with rather than just letting it grow on its own.
How much time? Probably not a lot unless the list grows quite
large indeed.

Yes. I know roughly how many objects it will contain. So array resizing
is not at all a problem (I know the resize operation is very few). But
even I don't think resize is time consuming , as it holds only the
reference, not the objects itself. And thus the array size
may be very less ( I have an approx 5000 size buffer).
so, for reference it may need 5000*ref_size memory which is much
smaller than 5000*object_size
That's why my question, as the array doesn't hold the object itself,
how important is to set the array size, or increment?
I have a
circular buffer which adds several objects from one end and removes
from other end through out the program. It is preferable if the
ArrayList holds the object itself.

The strategy is little different for the program, as you can see. The
program pushes certain objects into the circular buffer, perform some
operation on them and removes the older one. Thus lots of object
created pushed on buffer, and older one removed. So there I see two

One thing that stands out is the oddity of using an ArrayList
or Vector for a "circular buffer." An ordinary array would seem
more natural. (However, there's a bit of a language barrier here,
and it's quite possibly you use "circular buffer" to mean something
different than I do.)
Circular buffer is a static buffer over which references rotate to
denote start & end.
It is very much possible to implement it with array (not difficult at
all, in my openion).
I had uses ArrayList just to get immediate benifit of Iterator etc. I
will implement it using simple array.

1) No obvious hotspot, as the program doesn't run with the same object
on the loop (unlike most of the applications, or GUI's). Rather it
looks like a factory conveyor belt, where things are put in, operated
and finished.
2) Little overhead for then gc, as lots of new objects created and
processed need to be garbage collected.

Any tuning for gc can be done? any particular gc suitable for this kink
of oerations?

Toton, have you *measured* a performance problem? Or are
you merely imagining one?
No. I can't measure a performance for Java, as Java doesn't support by
value symantics for containers. However I had compared my C++
implementation with Java one. There is a difference. But I am not sure,
whether the difference is due to memory allocation or something else.
Maybe I will check in Java profiler about detail, with several run of
different size.
also I had a huge difference in C++, when I had transfered the program
from vector<Point*> to vector<Point> symantics. as in the second case,
allocator pre-allocates the memory for the objects with reserve, while
for the second case it pre-allocates only for pointers.
setting an object null, when it is no more in use anyway helps gc?
may be I will post some representative version of the program for clear

Eric Sosman