[2917] in java-interest

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

Re: Storage

daemon@ATHENA.MIT.EDU (Michael St. Hippolyte)
Fri Oct 20 14:02:16 1995

Date: Fri, 20 Oct 1995 11:47:41 -0400
To: java-interest@java.Eng.Sun.COM
From: mash@interport.net (Michael St. Hippolyte)


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

> ... 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.

I ran javah on the above as you suggested and discovered it is worst case in
memory usage: each byte takes a full 32 bits of storage.  But the header
doesn't show the per object overhead in the java runtime system, which is
significant, if I understand you correctly: the array object contains 1000 4
byte handles, each one to a separate chunk of memory containing a 4 byte
pointer to a method table plus the memory required for the object (in this
case, 12 bytes).  So the total memory allocation would be at least 20,000 bytes.

If this is true then perhaps it is better to design large collection classes
to allocate memory as base type arrays, like so:

	public class MidiMessageQueue {

		int[] midiMessage;

		public MidiMessageQueue(int length) {
			midiMessage = new int[length];
		}

		public int Length() {
			return midiMessage.length;
		}

		// etc.
	}

I would then have MidiMessage wrap an int so that retrieval from the queue
would be a simple assignment in all senses of the word.

Thanks for your time.  You "lowly Sun engineers" are doing a great job if
you ask me.

-- Michael



-
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