File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How much memory this array will utilize? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How much memory this array will utilize?" Watch "How much memory this array will utilize?" New topic
Author

How much memory this array will utilize?

Avais Aziz
Greenhorn

Joined: Oct 07, 2001
Posts: 16
How much memory this array will utilize?
String flower[]={"Rose","Jasmine","Tulip"};
Martin Rennix
Ranch Hand

Joined: Sep 30, 2001
Posts: 34
There is no easy answer because there is no "sizeof" operator in Java. Java stores extra run-time type information (RTTI) with each object, so it's not just a case of adding up the number of characters in each string.
Martin
Avais Aziz
Greenhorn

Joined: Oct 07, 2001
Posts: 16
Thanks! Martin
But it is still not clear to me ( I am just a beginner ).
So is there any way I can get the memory size even it is difficult to get it.
Thanks
Avais
Originally posted by Martin Rennix:
There is no easy answer because there is no "sizeof" operator in Java. Java stores extra run-time type information (RTTI) with each object, so it's not just a case of adding up the number of characters in each string.
Martin

Martin Rennix
Ranch Hand

Joined: Sep 30, 2001
Posts: 34
Not that I know of!
The amount of memory used is platform specific - remember Java is designed to be hardware independent.
Martin
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Why in the world would you NEED to know this?


"JavaRanch, where the deer and the Certified play" - David O'Meara
Martin Rennix
Ranch Hand

Joined: Sep 30, 2001
Posts: 34
Well, as an old-hand C programmer I liked knowing how much memory my structures took up! Maybe Sun were worried that people would find out the real memory footprint of each object! Just a thought.
Cindy, surely your opinion is purely subjective - we should never assume that a programmer will never need to do something.
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
The intent was that lots of C/C++ programmers have it so drilled into their heads that THEY have to control memory management, that they try to FORCE Java to do the same dance for no real good reason at all, just that they can't let go.
So if this person has a REAL reason for needing to know this, I would be interested in hearing it - but I am skeptical.
Avais Aziz
Greenhorn

Joined: Oct 07, 2001
Posts: 16
Hi! Cindy and Martin
Thanks for your replies.
I am not a programmer of any language so far. So
I am really new in your world. And I want to move
ahead with solid foundation. This topic was not clear
to me so I thought to disscuss not just ask.
I have visited this forum a few times before and I
think people here are very freindly and helpful.
That's why I asked again.
Avais
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
The correct "Java oriented" answer is - don't worry about it too much.
The array itself will not be that big, because it is just going to hold the object meta-data plus the references to the 3 Strings and their indexes. The Strings themselves will be held elsewhere.
Avais Aziz
Greenhorn

Joined: Oct 07, 2001
Posts: 16
Thanks Cindy for your insight.
Avais
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How much memory this array will utilize?
 
Similar Threads
Array Memory allocation
How much memory is utilize by an Array????
question about memory allocation.
utilization of swap memory
Undefined Variables