Results 1 to 7 of 7
- 10-10-2010, 03:45 PM #1
Member
- Join Date
- Oct 2010
- Posts
- 2
- Rep Power
- 0
How to determine the size of object (facilityExceptionData) in code below
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*)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")); } }
Any help in this regard is highly appreciated.
- 10-10-2010, 03:56 PM #2
Are you asking for the number of bytes used in memory?the size of object(HashMap)
I don't think there is any way to get that directly.
- 10-11-2010, 06:26 AM #3
Member
- Join Date
- Oct 2010
- Posts
- 2
- Rep Power
- 0
Hi Norm,
Yes, i want to know the memory space occupied(in Bytes) by facilityExceptionData.
- 10-11-2010, 08:27 AM #4
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.
- 10-11-2010, 10:09 AM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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.
- 10-11-2010, 01:13 PM #6
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.
- 10-11-2010, 01:59 PM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Similar Threads
-
Selecting min size and returning reference to object
By Saletra in forum New To JavaReplies: 1Last Post: 08-28-2010, 01:27 PM -
Setting frame size to the size of an image
By Yoruichi in forum AWT / SwingReplies: 5Last Post: 04-22-2009, 04:37 PM -
Object size
By kavithas in forum New To JavaReplies: 0Last Post: 11-30-2007, 12:00 PM -
size of a java object
By ravian in forum New To JavaReplies: 0Last Post: 11-12-2007, 09:19 AM -
OutOfMemoryError while creating a new object of file with size more than 150 MB
By Jamie in forum Advanced JavaReplies: 1Last Post: 05-20-2007, 08:52 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks