• Post Reply Bookmark Topic Watch Topic
  • New Topic

Memory doubt  RSS feed

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys....
Is there a way of finding out if a variable is on stack or heap???
 
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think a question you need to answer is "Why does it matter?"

Also, do you mean programatically, or by looking at the source code?
 
david colais
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@fred rosenberger : I mean if programatically it could be proven if a variable is in stack or heap?
 
Sheriff
Posts: 22846
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It isn't difficult for the programmer looking at the code: if it's a local variable then it's in the stack. If it's a class-level variable then it's part of an object which is in the heap. And this never changes.

There aren't any features in the API which give you any information about variables. There are plenty which give you information about the objects they refer to (and which are always in the heap, for what it's worth). Like the designers of the API, I can't envision any use cases for finding out where a variable is allocated. Do you have one? I too would be interested to know what it is.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!