Re: object byte size

From: Jesper Matthiesen (jmatthiesen[_fjen_)
Date: 11/28/03


Date: Fri, 28 Nov 2003 13:43:01 +0100


> Hi everyone.
> I'm currently implementing a Cache system.
> Limiting its capacity with the number of object makes no sense, since
> objects can have any size they want.
>
> So I'd like to limit its capacity in term of number of bytes allready
> cached.

OK - I'm not quite sure if this is is something you can use but have a look
at:

public void showMemoryInfo()
 {
  System.setProperty("java.compiler", "javac");
  Runtime runtime = Runtime.getRuntime();
        long totalMemory = runtime.totalMemory()/1024;
        long freeMemory = runtime.freeMemory()/1024;

  System.out.println("Total memory: " + totalMemory + " kilobytes.");
  Runtime.getRuntime().gc();
  System.out.println("Free memory: " + freeMemory + " kilobytes. Also: ");
  System.out.println(Math.round(
(((double)freeMemory)/((double)totalMemory)) * 100.0) + "%)");

 }

Regards Jesper



Relevant Pages

  • object byte size
    ... I'm currently implementing a Cache system. ... Limiting its capacity with the number of object makes no sense, ... I thought about serializing the object to an array of byte, ...
    (comp.lang.java)
  • Re: Steam engines - tender first?
    ... "astern" thus limiting their available power. ... Some branch line locos ... had full capacity as had all tank engines.. ...
    (uk.railway)
  • Re: England: the mother of modern sport
    ... grounds compared with those of Seria A etc. RH ... Are many Championship matches sold out then? ... capacity was a limiting factor for many of the teams. ...
    (uk.sport.cricket)