• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How much memory this array will utilize?

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How much memory this array will utilize?
String flower[]={"Rose","Jasmine","Tulip"};
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not that I know of!
The amount of memory used is platform specific - remember Java is designed to be hardware independent.
Martin
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why in the world would you NEED to know this?
 
Martin Rennix
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Cindy for your insight.
Avais
reply
    Bookmark Topic Watch Topic
  • New Topic