Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By ojn

Thread: A java problem

  1. #1
    Join Date
    Mar 2012
    Location
    Banglore
    Posts
    4
    Rep Power
    0

    Exclamation A java problem

    hi,

    Could any one tell me, how can we get(or display ) size of any variables(Instance or reference),
    which is going to store value in memory.
    Ex-.
    As like ,in C or C++ we have an operator sizeof(),
    it is used to find/display the total size of variable into memory
    and which return value in byte,

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,309
    Blog Entries
    7
    Rep Power
    20

    Default Re: A java problem

    There is no sizeof operator in Java; a.a.m.o.f. you shouldn't be interested in how many bytes an object takes.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Join Date
    Mar 2012
    Location
    Banglore
    Posts
    4
    Rep Power
    0

    Default Re: A java problem

    tnx,,,
    but i am not satisfied to ur answer....

    i know it, that there is no sizeof() operator in java.
    i am asking ,is any ulternate method is available in jave to find the size,occupied by any variable.

    & if it is not needed then plz tell me how much size these two array variable will occupie in memory.

    (1) int arr1[][]=new int[2][4];

    (2) int arr2[][]=new int[4][2];

  4. #4
    ojn
    ojn is offline Senior Member
    Join Date
    Aug 2008
    Location
    Stockholm, Sweden
    Posts
    119
    Rep Power
    0

    Default Re: A java problem

    As much as is needed.
    DarrylBurke likes this.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default Re: A java problem

    Quote Originally Posted by raj kumar singh View Post
    & if it is not needed then plz tell me how much size these two array variable will occupie in memory.

    (1) int arr1[][]=new int[2][4];
    Approximately 32 bytes plus a bit of overhead for the array structure.
    On a 32 bit system.
    Could be double that on a 64 bit system depending on how ints are stored.

    Quote Originally Posted by raj kumar singh View Post
    (2) int arr2[][]=new int[4][2];
    Ditto.

    Write code to handle the stuff you need to handle.
    Structure your code such that it is easy to understand and maintain.
    Don't hang onto data you don't need.

    If after all that you get an OOM then increase Xmx.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 4
    Last Post: 03-16-2012, 11:29 AM
  2. problem with java rmi
    By _rapt0r_ in forum New To Java
    Replies: 16
    Last Post: 12-31-2011, 05:41 PM
  3. Small problem with problem with Java, C++ parse program.
    By dragstang86 in forum New To Java
    Replies: 4
    Last Post: 10-30-2011, 03:43 AM
  4. Problem Display Jmenubar Java Se6 u23 versus Java SE6 u22
    By Ravanelly in forum Advanced Java
    Replies: 0
    Last Post: 01-07-2011, 09:36 AM
  5. Java problem help!
    By wexgal in forum New To Java
    Replies: 3
    Last Post: 10-26-2009, 12:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •