Solved

Are Hashtable and Treeset heavy on the resources (memory)

Posted on 2011-03-06
8
723 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
egit plugin on eclipse 8 82
iterator/ListIterator approach 17 39
How do I remove an object from a 3 40
Eclipse Java import and method not resolved 4 48
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

861 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