Results 1 to 7 of 7
  1. #1
    neetigya is offline Member
    Join Date
    Oct 2010
    Posts
    2
    Rep Power
    0

    Default How to determine the size of object (facilityExceptionData) in code below

    Java Code:
    Map<String,Map> facilityExceptionData = new HashMap<String, Map>(10000);
    List openTime = null;
    List closeTime = null;
    List dayOfWeek = null;
    List scheduledDateList = null;
    int facilityNum1 = 0;
    Map<String,Object> scheduleTableOne = null;
    while(rs.next()){ 
    if(!facilityExceptionData.containsKey("Facility_num_" + resultSet.getInt("Owner"))){
    if(null != scheduleTableOne && !scheduleTableOne.isEmpty()){
    scheduleTableOne.put("openTime",openTime ); 
    scheduleTableOne.put("CloseTime",closeTime );
    scheduleTableOne.put("DAYOfWeek", dayOfWeek);
    scheduleTableOne.put("ScheduleDate", scheduledDateList );
    
    }
    scheduleTableOne = new HashMap<String,Object>(5);
    openTime = new ArrayList(7);
    openTime.add(18);
    closeTime = new ArrayList(7);
    closeTime.add(18);
    dayOfWeek = new ArrayList(7);
    dayOfWeek.add(1); 
    scheduledDateList = new ArrayList(7);
    scheduledDateList.add(rs.getDate("SCHEDULED_DATE"));
    scheduleTable.put("Owner", 415402);
    scheduleTable.put("Usage", 1); 
    facilityNum = rs.getInt("Owner");
    facilityExceptionData.put("Facility_num" + facilityNum,scheduleTable);
    }else{
    openTime.add(rs.getInt("OPEN_TIME"));
    closeTime.add(rs.getInt("CLOSE_TIME"));
    dayOfWeek.add(rs.getInt("DAY_OF_WEEK"));
    scheduledDateList.add(rs.getDate("SCHEDULED_DATE"));
    
    }
    }
    How can i measure the size of object(HashMap) facilityExceptionData in above code . I have shown entry for Single Key in *facilityExceptionData * HashMap in above code snippet but in real scenario facilityExceptionData would hold 10000 Keys and value of these keys would be similar to object (*scheduleTableOne*)

    Any help in this regard is highly appreciated.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,891
    Rep Power
    25

    Default

    the size of object(HashMap)
    Are you asking for the number of bytes used in memory?
    I don't think there is any way to get that directly.

  3. #3
    neetigya is offline Member
    Join Date
    Oct 2010
    Posts
    2
    Rep Power
    0

    Default

    Hi Norm,

    Yes, i want to know the memory space occupied(in Bytes) by facilityExceptionData.

  4. #4
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    Quote Originally Posted by neetigya View Post
    Yes, i want to know the memory space occupied(in Bytes) by facilityExceptionData.

    the hashmap has a method called size() that returns only the number of elements in the collection. the size in bytes in the hashmap is not directly depending in the number of elements but in the size of the objects stored in it. what you could do is iterating through your collection and calculating the sum of the stored string objects or other referenced objects in it.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Apart from the "not really able to determine how big an object is", since how you handle Strings can affect how you calculate something like that (as an example)...scheduleTableOne should clearly be an object of some class representing that data. Using a Map like that is just plain wrong.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,891
    Rep Power
    25

    Default

    The size of the hashmap wouldn't include the size of the key and value objects that the hashmap contains references to. The data in the hashmap is just pointers and lists of pointers, the data pointed to is somewhere else.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Yep.
    But if those objects solely exist in the collection then I suppose you could argue they were part of the size of that collection...of course how you'd determine this...

    Profiling!

Similar Threads

  1. Replies: 1
    Last Post: 08-28-2010, 02:27 PM
  2. Setting frame size to the size of an image
    By Yoruichi in forum AWT / Swing
    Replies: 5
    Last Post: 04-22-2009, 05:37 PM
  3. Object size
    By kavithas in forum New To Java
    Replies: 0
    Last Post: 11-30-2007, 01:00 PM
  4. size of a java object
    By ravian in forum New To Java
    Replies: 0
    Last Post: 11-12-2007, 10:19 AM
  5. Replies: 1
    Last Post: 05-20-2007, 09:52 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
  •