Tutorial Addendum On Java - Beheading Ambiance

wargamesios kidsgamesios wordgamesios
 31 December 18:00   

    



    



    

The program seems to be confusing:

    



        

  • Why do I charge two altered methods to retrieve the anamnesis information?

        



  •     

  • Why are the methods alleged again 5 times?

        



  •     

  • Why are the press statements for the getMemoryInfo() adjustment not following

        

    the adjustment alarm statements immediately?

        



  •     



    



    

Answers to these questions are in the achievement of the program :

    

 

    

Print anamnesis advice - move = 0

    

Chargeless anamnesis = 1777568

    

Absolute anamnesis = 2031616

    

Best anamnesis = 134217728

    

Anamnesis acclimated = 254048

    

Print anamnesis advice - move = 1

    

Chargeless anamnesis = 1774712

    

Absolute anamnesis = 2031616

    

Best anamnesis = 134217728

    

Anamnesis acclimated = 256904

    

Print anamnesis advice - move = 2

    

Chargeless anamnesis = 1772496

    

Absolute anamnesis = 2031616

    

Best anamnesis = 134217728

    

Anamnesis acclimated = 259120

    

Print anamnesis advice - move = 3

    

Chargeless anamnesis = 1770280

    

Absolute anamnesis = 2031616

    

Best anamnesis = 134217728

    

Anamnesis acclimated = 261336

    

Print anamnesis advice - move = 4

    

Chargeless anamnesis = 1768064

    

Absolute anamnesis = 2031616

    

Best anamnesis = 134217728

    

Anamnesis acclimated = 263552

    

Get anamnesis advice - move = 0

    

Chargeless anamnesis = 1777568

    

Absolute anamnesis = 2031616

    

Best anamnesis = 134217728

    

Anamnesis acclimated = 254048

    

Get anamnesis advice - move = 1

    

Chargeless anamnesis = 1777568

    

Absolute anamnesis = 2031616

    

Best anamnesis = 134217728

    

Anamnesis acclimated = 254048

    

Get anamnesis advice - move = 2

    

Chargeless anamnesis = 1777568

    

Absolute anamnesis = 2031616

    

Best anamnesis = 134217728

    

Anamnesis acclimated = 254048

    

Get anamnesis advice - move = 3

    

Chargeless anamnesis = 1777568

    

Absolute anamnesis = 2031616

    

Best anamnesis = 134217728

    

Anamnesis acclimated = 254048

    

Get anamnesis advice - move = 4

    

Chargeless anamnesis = 1777568

    

Absolute anamnesis = 2031616

    

Best anamnesis = 134217728

    

Anamnesis acclimated = 254048

    



    



        

  • The aberration amid the getMemoryInfo() adjustment and printMemoryInfo() adjustment is

        

    that the getMemoryInfo() adjustment saves the anamnesis acceptance into arrays, while

        

    printMemoryInfo() adjustment prints the anamnesis acceptance ethics on the console. This is to show

        

    the appulse of the press statements, System.out.println(), on the anamnesis usage.

        



  •     

  • Calling the methods again is to see if there are any cilia additional than

        

    the appliance program cilia active that ability affect the anamnesis usage. As you

        

    can see from the output, the anamnesis acceptance was un-changed during the 5 calls to

        

    getMomeryInfo(). However, afterwards anniversary alarm to printMemoryInfo(), the chargeless anamnesis decreased

        

    by added than 2000 bytes. This suggests that the System.out.println() adjustment was leaving

        

    dead altar in anamnesis for the debris beneficiary to abolish them.

        



  •     

  • Calling the getMemoryInfo() at the alpha and putting the accompanying printing

        

    statements at the end is to abstain any appulse of press statements on the printMemoryInfo()

        

    calls.

        



  •     



    



    

Calculating Anamnesis Acceptance of an Array

    



    

The anamnesis infomation provided by the JVM can be acclimated to account the anamnesis usage

    

of data altar acclimated in the appliance program. In the afterward program, I approved

    

to account the anamnesis acceptance of an array:

    

 

    

/**

    

* MemoryUsage.java

    

* Absorb (c) 2002 by Dr. Yang

    

*/

    

public chic MemoryUsage {

    

clandestine changeless long fm = new long;

    

clandestine changeless long tm = new long;

    

clandestine changeless long mm = new long;

    

clandestine changeless long um = new long;

    

accessible changeless abandoned main(String a) {

    

Runtime rt = Runtime.getRuntime();

    

getMemoryInfo(rt,0);

    

long la = null;

    

continued s = allocateLongArray(la);

    

getMemoryInfo(rt,1);

    

System.out.println("Memory acceptance afore arrangement allocation:");

    

System.out.println(" Chargeless anamnesis = "+fm);

    

System.out.println(" Absolute anamnesis = "+tm);

    

System.out.println(" Best anamnesis = "+mm);

    

System.out.println(" Anamnesis acclimated = "+um);

    

System.out.println("Memory acceptance afterwards arrangement allocation:");

    

System.out.println(" Chargeless anamnesis = "+fm);

    

System.out.println(" Absolute anamnesis = "+tm);

    

System.out.println(" Best anamnesis = "+mm);

    

System.out.println(" Anamnesis acclimated = "+um);

    

System.out.println("Memory acceptance summary:");

    

System.out.println(" Allocated to the arrangement = "+s);

    

System.out.println(" Anamnesis acceptance access = "+(um-um));

    

System.out.println(" Aerial of individual arrangement = "

    

+(um-um-s));

    

}

    

accessible changeless abandoned getMemoryInfo(Runtime rt, int i) {

    

fm = rt.freeMemory();

    

tm = rt.totalMemory();

    

mm = rt.maxMemory();

    

um = tm-fm;

    

}

    



    

accessible changeless continued getMemoryInfo(Runtime rt) {

    

//rt.gc();

    

System.out.println("Getting JVM anamnesis infomation...");

    

continued fm = rt.freeMemory();

    

continued tm = rt.totalMemory();

    

continued mm = rt.maxMemory();

    

System.out.println(" Chargeless anamnesis = "+fm);

    

System.out.println(" Absolute anamnesis = "+tm);

    

System.out.println(" Best anamnesis = "+mm);

    

System.out.println(" Anamnesis acclimated = "+(tm-fm));

    

acknowledgment tm-fm;

    

}

    

accessible changeless continued allocateLongArray(long la) {

    

int s = 2*128*1024;

    

la = new long; // 2 MB bare for this array

    

acknowledgment 8*s;

    

}

    

}

    



    

 


Tags: program, array, system, methods, allocation, statements, memory, method, environment, public, printing

 memory, system, println, total, maximum, usage, static, getmemoryinfo, method, array, public, program, runtime, private, 254048get, printmemoryinfo, statements, methods, printing, , system out, free memory, maximum memory, total memory, memory used, memory usage, 2031616 maximum, memory 134217728, 134217728 memory, memory 2031616, memory info, info step, println memory, memory 1777568, 1777568 total, static long, new long, public static, 254048get memory, used 254048get, private static, println maximum, println total, getmemoryinfo method, printing statements, println free, 2031616 maximum memory, maximum memory 134217728, memory 134217728 memory, 134217728 memory used, total memory 2031616, memory 2031616 maximum, memory info step, memory 1777568 total, free memory 1777568, 1777568 total memory, private static long, println memory usage, 254048get memory info, memory used 254048get, used 254048get memory, println total memory, println memory used, println maximum memory, println free memory, public static long, public static void, java execution environment, array allocation system,

Share Tutorial Addendum On Java - Beheading Ambiance:
Digg it!   Google Bookmarks   Del.icio.us   Yahoo! MyWeb   Furl  Binklist   Reddit!   Stumble Upon   Technorati   Windows Live   Bookmark

Text link code :
Hyper link code:

Also see ...

Permalink
Article In : Computers & Technology  -  java