본문 바로가기

JAVA/Study...

sizeof Object

자바에서는 sizeof라는 개념이 없다.


1. 근데 궁금한게, double에서 d를 안붙이면, int 범위밖에 할당이 안된다. 왜??

 1.1 그러면, 4byte만 할당 되는건가? so, 한번 찍어보자!!! 라고 찾아보는데,

2. 객체의 크기를 찍어보는게 설명이 있어서 포스팅함.


Get size of object in memory


http://www.javapractices.com/topic/TopicAction.do?Id=83





이건 다른사람. 나중에 테스트 해보자.

 ㄴ 문제 해결!! int를 넣든, long을 넣든, 8byte임!!



public class Foo {

  public static void main (String[] args) {


  long[] n1 = new long[1024*1024];

  long[] n2 = new long[1024*1024];

  

    long free  = Runtime.getRuntime().freeMemory();

    long total = Runtime.getRuntime().totalMemory();

    long max   = Runtime.getRuntime().maxMemory();


    System.out.format("Total Memory : %6.2f MB%n", (double) total / (1024 * 1024));

    System.out.format("Free  Memory : %6.2f MB%n", (double) free  / (1024 * 1024));

    System.out.format("Max   Memory : %6.2f MB%n", (double) max   / (1024 * 1024));



//MAX : 1.75GB 

- total 121MB 

- 최소가 2.56mb / 1.92mb 이고 

그 다음부터는 할당한 만큼 커진다.

    

  }

}

해결 완료!!

반응형

'JAVA > Study...' 카테고리의 다른 글

UML 표기법 & 변수 표기법  (0) 2015.02.06
이클립스 (Tip)쉽게 사용하기  (0) 2015.02.06
쪽지시험 ①  (0) 2015.02.06
ASCII 와 escape문자  (0) 2015.02.06