Solved

Are Hashtable and Treeset heavy on the resources (memory)

Posted on 2011-03-06
8
716 Views
Last Modified: 2012-05-11
Hi,
I'm developing an application where I'm planning to use two hashtables with about a size of 1000 each. In the value, each value will be storing a treeset as an object containing about 1000 values. What I'd like to know is if this hashtable and treeset setup with such a large size makes the design very resource heavy?

As per my understanding , Hashtables usually start with a default initial capacity of about 11 (or 16). So 1000 in this case might mean a lot. Is that correct?

Thanks.
0
Comment
Question by:orazen12
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 92

Accepted Solution

by:
objects earned 167 total points
ID: 35053459
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35053995
On most modern computers where you can have several  hundred megabytes of memory and maybe even
more than 1 GB for your application these requirements do not seem to be prohibitive - you'll probably
have to increase the amount of allocated memory  in the options for virtual machine, say
-Xmx512M  or someting like that.
0
 

Author Comment

by:orazen12
ID: 35054596
Thanks ObJects.

For_Yan,
My server has 1 GB memory out of which 750MB is already being used (atleast that's what it is showing me in the webmin). Do you mean to say I'd need approx 1GB for this kind of operation or it should be ok with with my current system. It is doing a lot of other stuff too. Is there a way to check how much memory my system is using for this kind of operation?

Thanks.
0
 
LVL 13

Expert Comment

by:darren-w-
ID: 35055068
Hi,

Your computer would start using the swap if ram  is full, and this would then in turn slow down processing time as read-writes  from disk will be slower, apart from this it should not be a problem.

Darren
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 166 total points
ID: 35055113
I think the best way is first to write it in a straightforward way using all hashtables you need - make sure you are not getting java out of memory messages (provide sufficiently big number in -Xmx) and then observe - if you feel that your performance is too slow for your business  purposes, then try to monitor with your system means if your program is indeed doing a lot of memory swaps, then start thinking how to design your program to reduce memory size. My guess is that you'll not see too much swapping.
0
 
LVL 10

Assisted Solution

by:gordon_vt02
gordon_vt02 earned 167 total points
ID: 35058193
What kind of values are you storing?  The overhead of each Hashtable and TreeSet is fairly minimal so you need to figure out how much storage each object in the TreeSet requires and then you can estimate the amount of memory required.

Sk = memory for hash key
Se = memory for each tree entry
n = number of hash entries
m = number of tree set entries

App Mem = n * (Sk + (m * Se))

So, if your hash key is a long (8 bytes) and your TreeSets contain ints (4 bytes), with 1000 sets of 1000 items you would use:

1000 * (8 + (1000 * 4)) = 4,000,800 bytes = ~3.8 MB

If your value objects contain more complex data structures, especially variable length members like strings or arrays, you can come up with a good range and evaluate a worst-case scenario to make sure you have enough memory.  You aren't talking about a whole lot of data objects though, so unless each object is pretty big, you probably won't even need to modify the default JVM memory settings, and setting it to use at most the 250MB you have remaining should give plenty of room without swapping.
0
 
LVL 10

Expert Comment

by:gordon_vt02
ID: 35058201
Oops, flipped the 0 and 8 in that calculation.  Should be 4,008,000 bytes = ~3.8 MB.
0
 

Author Closing Comment

by:orazen12
ID: 35125537
Thanks.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now