Re: How to give selective access to the methods in a class?
- From: "toton" <abirbasak@xxxxxxxxx>
- Date: 9 Aug 2006 22:00:09 -0700
Eric Sosman wrote:
toton wrote On 08/09/06 10:24,:Yes, its JVM's worry. I know that. My worry is that, do JVM really
[...]
One more question, slightly out of topic.
ArrayList can reserve memory for certain size. I expect that memory is
to reserve only the reference, not the object itself (unlike C++
containers where u can reserve for the cobect itself).
Correct. Object instances in Java exist "somewhere
else," and the only things the program manipulates directly
are references and primitives.
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.
worry to keep frequently accessed objects in nearby places?
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.
The strategy is little different for the program, as you can see. TheI 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.
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
problems,
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?
As you know by now, the ArrayList holds references andIf the contaner class objects resides nearby in memory (may not be
not instances. I don't see why you would prefer things to
be otherwise -- but in any event, they aren't.
adjascent unlike array with premitives), it is good for most
programming, as most of the time program iterates over the container
classes and do operation.
--
Eric.Sosman@xxxxxxx
.
- Follow-Ups:
- Re: How to give selective access to the methods in a class?
- From: Eric Sosman
- Re: How to give selective access to the methods in a class?
- References:
- How to give selective access to the methods in a class?
- From: toton
- Re: How to give selective access to the methods in a class?
- From: Eric Sosman
- Re: How to give selective access to the methods in a class?
- From: toton
- Re: How to give selective access to the methods in a class?
- From: Eric Sosman
- Re: How to give selective access to the methods in a class?
- From: toton
- Re: How to give selective access to the methods in a class?
- From: Eric Sosman
- How to give selective access to the methods in a class?
- Prev by Date: Re: Output Stream Help
- Next by Date: Re: do loop bug?
- Previous by thread: Re: How to give selective access to the methods in a class?
- Next by thread: Re: How to give selective access to the methods in a class?
- Index(es):
Relevant Pages
|