[2908] in java-interest

home help back first fref pref prev next nref lref last post

Re: Storage

daemon@ATHENA.MIT.EDU (Jim Graham)
Fri Oct 20 00:55:11 1995

Date: Thu, 19 Oct 1995 20:00:21 -0700
From: flar@bendenweyr.Eng.Sun.COM (Jim Graham)
To: java-interest@java.Eng.Sun.COM, mash@interport.net


> I have a question concerning how Java deals with byte-aligned data.
> If allocate an array of 1000 of the following object...

Java does not allocate arrays of objects.  It allocates arrays of
pointers to objects.  If you do "Object[] a = new Object[100]", then
a[0] will be null until you assign an object to it.  So, an array
of 1000 things will take about 4000 bytes for the 1000 handles that
are allocated.  As for how big the things you stuff in there are, that
would be implementation dependent.  Try using javah to generate a
C interface header file for your class to see how the data is being
aligned.  Also keep in mind that allocating any object will allocate
a handle for it from the handle table and that will take 4 bytes for
the (relocatable) pointer to the object and 4 bytes for a method table
pointer in our implemenation - per object that you allocate.

> 	public class MidiMessage {
> 		public byte status;
> 		public byte data1;
> 		public byte data2;
> 	}
> 
> ...will I be allocating 3000, 4000, or (God forbid) 12000 bytes of machine
> memory?  Am I better off packing the bytes myself into an int?  Any guidance
> would be appreciated.  Thanks!

You may be better off packing the bytes into ints or allocating 3 separate
arrays of bytes...

				...jim
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post