[3816] in java-interest

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

Where does the allocation happen.

daemon@ATHENA.MIT.EDU (Pradeep Badri)
Tue Nov 28 22:17:20 1995

From: Pradeep Badri <pbadri@cisco.com>
To: java-interest@java.sun.com
Date: Tue, 28 Nov 95 16:25:47 PST
Cc: pbadri@cisco.com (Pradeep Badri)


Hi,

When i allocate memory for an object/array, where does it happen.
in the heap or in the stack.

eg. 
		 byte []  func() {
			byte [] stackVar ;  // want it on stack.
			byte [] heapVar ;  // want it on heap.

			stackVar = new byte[200] ;
			heapVar = new byte[200] ;
			...........
			return heapVar ;  // note that i want to pass this around.
		}

I really want the allocation to happen in the stack and not
in the heap.  because i might call func frequently and don't want
to fragment memory by frequent allocation/deallocation.

An equivalent C code is 
		 char *func() {
			char  stackVar[200] ;  // want it on stack.
			char * heapVar ;  // want it on heap.

			heapVar = new char[200] ;
			...........
			return heapVar ;
			.............
		}

So how exactly do i make sure that allocation happens in stack 
and sometimes i would like to allocate it on heap so that i can
pass it on to other functions.

I read through the spec and saw a keyword 
		"transient" and "volatile"

Do i have to use "transient" to allocate space in stack
and by default allocation happens on heap.

Appreciate any help.

thanks,
-pb.

Pradeep Badri.
Cisco Systems.
408-526-8819.
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

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