The Artima Developer Community
Sponsored Link

Java Answers Forum
dynamic memory allocation in stack and heap

3 replies on 1 page. Most recent reply: Apr 11, 2003 1:37 PM by Matt Gerrans

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Erik Norman

Posts: 2
Nickname: erikfzr
Registered: Apr, 2003

dynamic memory allocation in stack and heap Posted: Apr 11, 2003 7:52 AM
Reply to this message Reply
Advertisement
Hi!

I am an applied science student.
We are dealing with the memory allocation models of creating new objects, calling methods, etc.

I have one specific question (for now):

If the type of the reference variable of an object is changed by type casting to the type of its super class, where in the memory (heap, stack or similar) is this type saved?

Have a look at this example of memory allocation:
http://www.geocities.com/erikfzr/exampleofmemoryallocation.pdf

Thanks for any help!

Erik


Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: dynamic memory allocation in stack and heap Posted: Apr 11, 2003 8:45 AM
Reply to this message Reply
In the heap.

Erik Norman

Posts: 2
Nickname: erikfzr
Registered: Apr, 2003

Re: dynamic memory allocation in stack and heap Posted: Apr 11, 2003 11:57 AM
Reply to this message Reply
where exactly in the heap,
it isn't in the class reference, because another reference variable could still refer to the object on the heap,
so where in the heap is this information stored?

Erik

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: dynamic memory allocation in stack and heap Posted: Apr 11, 2003 1:37 PM
Reply to this message Reply
Hmm...

Could you post a little snippet of exactly what you mean. The link you gave doesn't seem to be available.

If what you mean is something like this:
   String s = "This is a string.";
   Object o = s;

And your question is "where is the information that says o is an Object?" then I would say that there is a reference variable on the stack of type Object, which refers to an instance of a String in the heap. So the object on the heap knows what it is, but the reference variable on the stack isn't as certain about what it is referring to. The object is always a String regardless of what type(s) of reference refer to it.

Flat View: This topic has 3 replies on 1 page
Topic: EOFException Previous Topic   Next Topic Topic: need help...I'm new.

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use