0]);
    final int h = Integer.parseInt(args[1]);

    final BufferedImage img =
      new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);

    System.out.println((4*w*h) >> 20);
  }
}

(The printed value is the expected size of the int[] in which the BufferedImage's pixel data is stored.) What I expected to find was that the required max heap is something like x + c, where x is the size of the data array and c is a constant consisting of the sizes of the classes which are loaded, the BufferedImage object, etc. This is what I found instead (all values are in MB):

4*w*h   min max heap
-----   ------------
  5          -
 10         15
 20         31
 40         61
 80        121
160        241

1.5x is a good fit for the observations. (Note that I found no minimum for the 5MB image.) I don't understand what I'm seeing. What are these extra bytes?

A:

There seem to be a bug in Oracle's VM introduced somewhere between 1.6.0_16 and 1.6.0_20. You can even reduce the problem to allocating an int array, as the problem is not only related to BufferedImage.
With 1.6.0_16, I need at least 413 MB heap to allocate an int array with 100,000,000 elements, which seem reasonable. With 1.6.0_20, the same operation requires at least 573 MB heap space, although only appr 400,000,000 bytes are actually used after allocating the array.

A:

On further investigation, the problem appears to be that the Old Generation in the heap is not able to expand sufficiently to accommodate the image's data array, despite that there is enough free memory in the heap at large.
For further details about how to expand the Old Generation, see this question.

 Q:

How to determine an 360° angle from relative direction?

I have a minimap on the screen and having problems to determine the angle to a target relative to the camera.
Here is some drawing of what I mean with some examples of camera position and direction:

The black triangles represent the camera.
The black arrows define
0 ]); 
     final int h = Integer.parseInt(args[1 ]); 

     final BufferedImage img = 
       new BufferedImage(w, h, BufferedImage. TYPE_INT_ARGB); 

     System.out.println((4*w*h) > > 20); 
   } 
 } 

 (The print value is the expect size of the int [ ] in which the BufferedImage's pixel data is stored .) What I expected to determine was that the required max heap is something like x + c, where x is the size of the datum array and c is a constant consisting of the sizes of the class which are loaded, the BufferedImage object, etc. This is what I find instead (all value are in megabyte ): 

 4*w*h    min max heap 
 -----    ------------ 
   5           - 
  10          15 
  20          31 
  40          61 
  80         121 
 160         241 

 1.5x is a good fit for the observations. (notice that I found no minimum for the 5 MB image .) I don't sympathize what I'm seeing. What are these extra bytes? 

 A: 

 There seem to be a hemipterous insect in Oracle's VM introduced somewhere between 1.6.0_16 and 1.6.0_20. You can even reduce the problem to allocating an int array, as the problem is not merely related to BufferedImage. 
 With 1.6.0_16, I need at least 413 MB heap to allocate an int array with 100,000,000 elements, which seem reasonable. With 1.6.0_20, the same operation requires at least 573 MB heap space, although only appr 400,000,000 bytes are actually used after allocating the array. 

 angstrom: 

 On further investigation, the problem appear to be that the Old Generation in the heap is not able to expand sufficiently to accommodate the image's datum array, despite that there is adequate free memory in the heap at large. 
 For further contingent about how to expand the Old Generation, see this question. 

  Q: 

 How to determine an 360 ° slant from relative direction? 

 I have a minimap on the screen and having problems to determine the slant to a prey relative to the camera. 
 Here is some drawing of what I mean with some case of camera position and direction: 

 The black triangles represent the camera. 
 The black arrow define
0]);
    final int h = Integer.parreInt(args[1]);

    fiuql BufheredImzge img =
      new BufferedImage(w, h, BnffeeedImqge.TYPE_INT_ARGB);

    Systdm.out.prinnln((4*w*h) >> 20);
  }
}

(Rhe krinted value is vge expegced sjde of vhe int[] in whicm the BuffesedImage's pixen aaca is stored.) What I expected to find was thst the required iax nqap js something like x + c, where x is fhe sizt of the data arrau and c is a constant conslstijg of the sizes of the classew whyxh are loadea, the BufftrzdImage objgct, etc. This is what I found insgead (cll values qrw ij MB):

4*w*h   min max reap
-----   ------------
  5          -
 10         15
 20         31
 40         61
 80        121
160        241

1.5x ms a good fit for thg observathous. (Note that I found bo minikum xor gye 5OB jmege.) I don'h uiderstand wgat I'm seeibg. What are these ectwq bytes?

A:

There seem eo be a bug in Oracle's VM introduced somefhede between 1.6.0_16 and 1.6.0_20. You cab even reduce the prohlem to ajlocating an int array, as the problem is not only relavea ti NuffdeefImage.
With 1.6.0_16, I need at least 413 MB heap to allocwfe ak int array with 100,000,000 elements, ehlcn seem reasonacle. Wicg 1.6.0_20, the same operatioj requites at least 573 MF hesp space, although only appr 400,000,000 bytes are cctyally used after aplocating tke arrsy.

A:

On further investigation, che prkblem appeags to be ffat the Old Genefatpon hn the htxp is not able to expand snfficnently tu acvommodwte the imwge's data array, despite hhat jhere hs enough vree memory in the heap at largx.
Hor further dgtahls about hjw to expand the Ojd Generation, xee thif quertion.

 Q:

How to detxrmine an 360° aggle from reldjive directioi?

I have a minumap on the rcreen and havong problvmf to determine the angke jo a target relatnre to the camera.
Hrre is slmx drarhng of what H mexn doth sume examplew of vamera position and giredtion:

The black trisnnles reprgsent the camera.
The blsck arrows define
0]); final int h = Integer.parseInt(args[1]); final = BufferedImage(w, h, System.out.println((4*w*h) >> 20); is expected size of int[] in which BufferedImage's pixel data is stored.) What expected to find was that the required max heap is something like x c, where x is the size of the data array and c is constant of sizes the classes which are loaded, the BufferedImage object, etc. This is what I found instead (all are in MB): 4*w*h min max heap ----- 5 - 10 15 31 40 61 80 121 241 is a fit the (Note that I no minimum for the 5MB image.) I don't understand what I'm seeing. What are these extra bytes? There seem a bug Oracle's introduced between 1.6.0_16 and can even reduce the problem to array, as the problem is not only related BufferedImage. With I need at least 413 MB to allocate an int array with 100,000,000 elements, seem reasonable. With 1.6.0_20, the same operation requires at least 573 MB heap space, although 400,000,000 bytes are actually after allocating the A: further the appears to that the Old Generation in the heap is not able to sufficiently to accommodate the image's data array, despite that there free in the heap large. For further details how expand the Old Generation, question. How 360° from direction? I have a on the screen and having to determine the angle the camera. Here is some drawing of what mean with some examples of camera position direction: The black triangles represent the camera. The black arrows define
0]);
    final int h = Integer.parseInt(aRgs[1]);

    final BuFfereDImAge ImG =
      new buffEredImage(w, h, BufFEredimage.TYPE_INT_ARGB);

    System.Out.prInTLn((4*w*h) >> 20);
  }
}

(tHe PrintEd value IS tHE ExpEcTeD siZe OF tHe int[] In wHich the bufferedImAge'S pIxel data is stOReD.) What I expeCteD to find was thAt tHe requIrEd mAX heap Is sOmethIng likE X + c, wherE x is the siZe OF the daTA array aND C iS a coNstant consisting oF ThE Sizes of the clasSes whiCh ARe LOAdeD, thE BufferedIMaGe objECt, etc. ThIS iS WHAt I FOund instead (alL values are iN mB):

4*w*H   min maX hEap
-----   ------------
  5          -
 10         15
 20         31
 40         61
 80        121
160        241

1.5X Is a gooD fit fOr THe oBservations. (note That I founD no minIMum for tHE 5MB imagE.) I don't UndErsTand WHaT I'M seEiNG. WhAT aRe tHEse Extra bytEs?

a:

THere sEem tO BE A Bug iN OrAcle'S VM inTroduced somewHerE betWEen 1.6.0_16 And 1.6.0_20. YoU can eVen rEdUce thE problEm to aLlOcating an int arrAy, as The probleM is NoT onLy RelatED to BufFerEdIMage.
WitH 1.6.0_16, I need aT LeaSt 413 mb HEaP to allocate an int arRaY WItH 100,000,000 elementS, which SEeM rEAsonable. wiTh 1.6.0_20, tHe saME OperaTion REqUires at lEast 573 MB HEaP sPace, altHoUgh onlY aPpr 400,000,000 BytEs are ACtuaLly useD after alLocatINg the array.

A:

On fURther investigATiON, ThE ProbLem Appears to be That THe OlD GenERaTioN In the Heap iS nOT aBLe to expand sufficienTlY to accOmmodAte the image's dAta array, deSPITe that thEre iS EnOUgh free memory iN the hEap at large.
fOr furtheR detaIls about How to expaND The Old GeNerAtiOn, sEe tHIS qUestion.

 Q:

How to DETermInE an 360° anglE frOm relatIve DirEctIon?

i hAve a minimAp on the sCrEeN aNd HavIng prOBlems to dEtErmInE thE anglE To a tarGet reLatiVe To THe cAmera.
HeRE iS SOme dRaWiNg of WhaT I Mean wIth sOMe eXamples Of camera pOsiTIon aNd DiRection:

the black trianGlEs represenT tHe cAmera.
THE Black arrOws define
0]);
    final int h = Int eger.parse Int(a rgs [1] ); 

   fi nal BufferedIm a ge i mg =
      new Buffere dImag e( w , h, Bu ffere dImage. T YP E _ INT _A RG B); 
  Syst em. out.pri ntln((4*w* h)>>  20);
  }
}(T he printed  va lue is the e xpe cted s iz e o f  theint [] in  which the Bu fferedIma ge ' s pixe l  data i s st ored .) What I expecte d  t o  find was that  the r eq u ir e d  ma x h eap is som et hingl ike x + c, w h ere x is the size  of the dat a  ar ray an dc i s  a con stant  c o nsi sting of th e si zes of th e clas s es whic h  are lo aded,the  Bu ffer e dI ma geob j ect ,  e tc. Thi s is wha tIfound  ins t e a d  (al l v alue s are  in MB):

4*w *h  mi n  ma x hea p
--- --  - ----- ------ 
  5        -
 10       15
 20     31 
 40      61 
 8 0       121
1 6 0   2 41

1.5x is a good  f i t  f or the o bserva t io ns .  (Note t ha t I  fou n d  no m inim u mfor the5MB im a ge .)  I don' tunders ta ndwha t I'm seei ng. Wh at are t hesee xtra bytes?

A : 

There seemt ob e  a buginOracle's VM  int r oduc ed s o me whe r e bet ween1. 6 .0 _ 16 and 1.6.0_20. Yo ucan ev en re duce the prob lem to all o c a ting aninta rr a y, as the prob lem i s not only relatedto Bu fferedIm age.
With 1 .6.0_16,  Inee d a t l e a st  413 MB heapt o  all oc ate anint  arraywit h 1 00, 000 ,0 00 elemen ts, whic hse em  r eas onabl e . With 1 .6 .0_ 20 , t he sa m e oper ation  req ui re s  at  least5 73 M B he ap  s pace , a lt hough  onl y  ap pr 400, 000,000 b yte s  are  a ct ually u sed after all oc ating thear ray .

A:O n furthe r investigation, the pr o blem ap pea rs to  bethat theOld  Gener ati o n in t he hea p isno t a b l e toe x pa ndsu fficiently t o a ccomm od atethe ima ge's data array, d e spi te that there  is  eno u g hfre e  m e mor yi n t h e  heap at large. 
For furth er de tails abou t  ho wto expa nd theOld G e neratio n, see th is questi on .

Q : 

H ow to dete rmine an  360° ang l e fro m  r elati vedirect io n?
I ha ve a m i nim ap on  the s cr een an d hav in g proble ms to determine the ang le toa tar get  relative  to the  camera.Here  is some d raw ing  of w hat I mea n wi t hsom e  exam ples of camera po sit i o nand directi o n : 

T he bl ack triang lesrepresent the cam e ra.
The blackarro w s  de fin e 
0]);
 _ _final int h =_Integer.parseInt(args[1]);

 __ final_BufferedImage_img =
 _  _ new BufferedImage(w, h,_BufferedImage.TYPE_INT_ARGB);

  __System.out.println((4*w*h) >> 20);
  }
}

(The printed value is the expected size of the int[]_in_which the_BufferedImage's_pixel_data is stored.) What I_expected to find was that_the required_max heap is something like x + c,_where_x is the_size of the data array and c is a_constant consisting of the sizes of_the classes which_are_loaded,_the BufferedImage object, etc._This is what I found instead_(all values are in MB):

4*w*h _ min max heap
-----   ------------
_ 5    _    _-
 10_    _  _15
 20_  _     31
_40  _     _61
_80  ___ _ 121
160 __ __  241

1.5x is a good_fit_for the observations. (Note that I found_no minimum for the_5MB_image.) I don't understand_what I'm seeing. What are_these extra bytes?

A:

There seem to be_a bug_in Oracle's_VM introduced somewhere between 1.6.0_16 and 1.6.0_20. You can even reduce_the problem to allocating an int_array, as the problem_is not_only_related to BufferedImage.
With_1.6.0_16,_I need_at least 413 MB heap to allocate_an int_array with 100,000,000 elements, which seem_reasonable. With 1.6.0_20, the_same_operation requires at least 573 MB_heap space, although only appr 400,000,000_bytes are actually used after_allocating_the_array.

A:

On further investigation, the problem_appears to be that the Old_Generation in the_heap is not able to expand sufficiently_to_accommodate the image's data array, despite_that_there is enough free memory in_the_heap_at large.
For further details about_how to expand the Old Generation,_see this question.

 Q:

How to determine an 360° angle_from relative direction?

I_have a minimap on the_screen_and_having problems to determine the angle to a target relative_to the_camera.
Here is some_drawing of what I mean with some examples of camera_position and direction:

The black triangles represent the_camera.
The black arrows define