Results 1 to 11 of 11
  1. #1
    robby14 is offline Member
    Join Date
    Feb 2010
    Posts
    15
    Rep Power
    0

    Default loading data in memory

    Hi,
    I am currently loading the contents of a file in a hashtable, as during runtime I would need to check if an object exists in the file. It works fine like that however I am preoccupied that if the file gets large, which it is likely to be, it might cause a memory leak. Could anyone suggest a suitable way to go around this problem.

    thanks

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by robby14 View Post
    however I am preoccupied that if the file gets large, which it is likely to be, it might cause a memory leak.
    Why do you feel this is a risk?


    Could anyone suggest a suitable way to go around this problem.
    Profile the app if you're worried about this.

  3. #3
    robby14 is offline Member
    Join Date
    Feb 2010
    Posts
    15
    Rep Power
    0

    Default

    It would cause the application to fail. Moreover, there would only be part of the data in memory which would make the sytem operation not 100% correct

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  5. #5
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Your requirements are not quite clear. Do you want to check the file just one time for the existence of a particular piece of data? Or do you want to keep the contents of the file in memory, and be able to check quickly for any specified piece of data? If it's the latter, then loading the file into a HashTable sounds like a good strategy (although if the file sizes are really huge, you may have to pass an argument to java requesting more memory at startup). If it's the former, then it may be better to just do a scan-and-compare loop on the file.

    -Gary-

  6. #6
    robby14 is offline Member
    Join Date
    Feb 2010
    Posts
    15
    Rep Power
    0

    Default

    thanks for your guidance. Its the latter. I need to keep it in memory to check consistently. Could you please guide me into what commands I am to use in order to give more memory to java pls.

    thanks

  7. #7
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    java -Xms512m MyProgram to start with 512 megabytes.

    -Xms to specify the initial allocation pool, or -Xmx to specify the maximum.

    java - the Java application launcher

    -Gary-

  8. #8
    robby14 is offline Member
    Join Date
    Feb 2010
    Posts
    15
    Rep Power
    0

    Default

    is it possible to write some kind of command in the code itself, so that when other users can just double click on the jar file and thats it?

  9. #9
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    You can package your code in a JAR file. Google will help you. Really, though, how big do you expect these files to be? I'd be very surprised if they were over one megabyte, and by default Java starts with a 2MB pool and a max of 64MB. If your files are really too large for the defaults, you may want to consider parsing your data and loading it into a SQL database rather than keeping an in-memory HashTable.

    -Gary-

  10. #10
    robby14 is offline Member
    Join Date
    Feb 2010
    Posts
    15
    Rep Power
    0

    Default

    ok thank you very much for your help

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by robby14 View Post
    thanks for your guidance. Its the latter. I need to keep it in memory to check consistently. Could you please guide me into what commands I am to use in order to give more memory to java pls.

    thanks
    It's much better to avoid trap the memory in to your application as much as possible. I mean if you really know that, your application use lots of memory then better to revisit on your design.

Similar Threads

  1. error while retrieving data from data base
    By kirtesh4u in forum New To Java
    Replies: 5
    Last Post: 11-15-2008, 05:10 PM
  2. Replies: 0
    Last Post: 10-31-2008, 03:13 PM
  3. Data Sorting in a .data file using java
    By stutiger99 in forum New To Java
    Replies: 2
    Last Post: 10-08-2008, 03:52 AM
  4. Replies: 2
    Last Post: 08-21-2008, 08:33 PM
  5. Memory
    By mew in forum CLDC and MIDP
    Replies: 0
    Last Post: 12-28-2007, 12:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •