Craig,
Like C/C++, Java uses strong type constraints to prevent
programmers from accessing data in an inconsistent way
(e.g. casting objects). Unlike C/C++, Java prevents you
from having direct access to program memory. In C/C++,
it is common to use a pointer to locate a variable in memory
and then to mainpulate the pointer to process the data in it.
For Java, all Java objects are stored in *heap* that makes
programmers have no idea of how the JVM represents objects in
memeory. This adds another level of security from being attacked
or hacked. It is why you can't calculate the memory location and
then access the right object--objects are stored in *heap*.
What you can do is through a method of the object passing the
array object as a reference to the other object.
Kennis
B. Craig Taverner wrote:
>
> Hi,
>
> I'm dealing with a performance issue in java where it appears that
> performance is noticably affected by the fact that many (thousands) of
> relatively small objects need to be created very quickly (multiple small
> memory allocations). From my C/C++ background I would have considered
> solving this problem by allocating the objects in reasonable sized blocks
> of objects (single alloc for many objects to minimize system calls).
> Individual objects could still be accessed (perhaps
> calloc/sizeof/typecast) and could then continue to be referenced in the
> normal way (hashtables, vectors, trees, etc).
>
> However, I do not see any obvious way to achieve this in java. You cannot
> simply allocate a chunk of memory (you also cannot know the object size,
> or typecaste the memory to the object type). If I allocate an array of
> objects, I'm simply allocating an array object that contains references to
> the correct object type, but does not actually contain those objects, and
> they still need to be created.
>
> Does anyone know of a good way to solve this problem? Any suggestions
> around the issue of object creation performance are welcome.
>
> Cheers, Craig
>
> ------
> "I like to believe that people in the long run are going to do more to
> promote peace than our governments. Indeed, I think that people want
> peace so much that one of these days governments had better get out of
> the way and let them have it."
> -- Dwight D. Eisenhower
>
> ======================================================================
> Craig Taverner ------====== Email:[EMAIL PROTECTED]
> ComOpt AB ------======== Tel: +46-42-212580
> Michael Löfmans Gata 6 ------========== Fax: +46-42-210585
> SE-254 38 Helsingborg ------======== Cell: +46-708-212598
> Sweden ------====== http://www.comopt.com
> ======================================================================