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




Eric Sosman wrote:
toton wrote On 08/09/06 10:24,:
[...]
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.
Yes, its JVM's worry. I know that. My worry is that, do JVM really
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.
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
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 and
not instances. I don't see why you would prefer things to
be otherwise -- but in any event, they aren't.
If the contaner class objects resides nearby in memory (may not be
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

.



Relevant Pages

  • [RFC] page replacement requirements
    ... Submitting too much I/O at once can kill latency and even lead to deadlocks when bounce buffers are involved. ... Must be able to deal with multiple memory zones efficiently. ... When on completion of the write to their backing-store the reference bit is still unset a callback is invoked to place them so that they are immediate candidates for reclaim again. ... For traditional page replacement algorithms this is not a big issue since we just implement per zone page replacement; ...
    (Linux-Kernel)
  • Re: Java or C++?
    ... >> CTips wrote: ... GC can only kick in when the last reference has ... If f was already bound to a lot of memory when it enters do-it then ... > more than the extra memory leaked because of sloppy manual deallocation]. ...
    (comp.programming)
  • Re: 4-way Opteron vs. Xeon-IBM X3 architecture
    ... >>>The point here is that the issue concerns both speed AND capacity. ... >As to the reference, the message header points right back in this thread, ... >>>As you may suspect, I read plenty about memory systems, and I would ... >>>from the enthusiast market and assumed that it would work in the server ...
    (comp.sys.ibm.pc.hardware.chips)
  • Re: How to give selective access to the methods in a class?
    ... different memory locations at different times. ... The reference still leads to the ... as the container doesn't hold the object itself. ... program pushes certain objects into the circular buffer, ...
    (comp.lang.java.programmer)
  • Re: Garbage Collection Issues in long-standing services
    ... I would agree that I must be holding on to some references, ... store a reference to CS so that it can use it to send data back to the client. ... > By starting another process that allocates memory, ... it does not aggressively cleanup until the amount of physical memory ...
    (microsoft.public.dotnet.languages.csharp)