Article View: borland.public.jbuilder.java.language
Article #18864Re: arrays of objects
From: Kevin B
Date: Thu, 09 Apr 1998 00:00
Date: Thu, 09 Apr 1998 00:00
40 lines
1760 bytes
1760 bytes
James, OK, this brings up an important point (for someone new to Java like me that is <g>). So what you are saying is that there is no way to actually preallocate an array of objects like you can in C++? Even when I declare an array of objects I MUST still allocate each object of the array individually? It's ALWAYS like an array of pointers? Hmmm... if so, this can be a real performance problem when you are working with very large arrays. The memory management overhead of creating that many individual objects is very slow. Is there a way to avoid having to create all of those objects individually? Thanks!!! Kevin James V. Reagan <jreagan@jpartners.com> wrote in article <6ggepc$e11$1@Nntp1.mcs.net>... > > In Java everything is a 'reference' (except for primitive types, of course). > References are just pointers (in fact, in C++ references are implemented > as pointers under the hood). You just can't do pointer arithmetic with > references (a la C++). > > So, all you would need to do is: > > Object[] array1 = new Object[10000]; > Object[] array2 = new Object[100]; > > Object obj = new Object(); > array1[0] = obj; > array2[0] = obj; > > and voila you have your entries from two arrays referencing a single > object. >
Technical Details
Message-ID:
<01bd63b1$2001c4f0$b2c33081@boylankl>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<01bd62ec$0c857a40$b2c33081@boylankl> <6ggepc$e11$1@Nntp1.mcs.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,d90257f1ce51c897 X-Google-Attributes: gidf74b3,public From: "Kevin B" <boylank@computer.org> Subject: Re: arrays of objects Date: 1998/04/09 Message-ID: <01bd63b1$2001c4f0$b2c33081@boylankl> X-Deja-AN: 342390823 References: <01bd62ec$0c857a40$b2c33081@boylankl> <6ggepc$e11$1@Nntp1.mcs.net> Organization: Another Netscape Collabra Server User Newsgroups: borland.public.jbuilder.java.language