Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #10116

Re: Size of an arraylist in bytes

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From Eric Sosman <esosman@ieee-dot-org.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Size of an arraylist in bytes
Date Sun, 20 Nov 2011 16:30:41 -0500
Organization A noiseless patient Spider
Lines 28
Message-ID <jabri2$763$1@dont-email.me> (permalink)
References <e9dcfb2d-dfef-4ae6-9d9f-979a8f08b962@t36g2000prt.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Sun, 20 Nov 2011 21:30:42 +0000 (UTC)
Injection-Info mx04.eternal-september.org; posting-host="HSlJAUb3pGXi3i7ZL/HoAw"; logging-data="7363"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18bOKD1rgALSIjwtAjf4YWF"
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:8.0) Gecko/20111105 Thunderbird/8.0
In-Reply-To <e9dcfb2d-dfef-4ae6-9d9f-979a8f08b962@t36g2000prt.googlegroups.com>
Cancel-Lock sha1:vQFXZQwpwnODtRMcAxax7bGVJ80=
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:10116

Show key headers only | View raw


On 11/20/2011 4:01 PM, sara wrote:
> Hi All,
>
> I create an Arraylist<Integer>  tmp and add some integers to it.
> Afterward, I measure the size of tmp in bytes (by converting tmp to
> bytes array). Assume the result is byte[] C. However, when I update an
> element of tmp, and measure size of tmp in bytes again, the result is
> different than C!
> Why this is the case?

     See markspace's response.  Another possible point of confusion:
The ArrayList does not actually contain objects, but references to
those objects -- that's why the same object instance can be in three
ArrayLists, two Sets, and a Map simultaneously.  In fact, the same
Integer object could appear forty-two times in a single ArrayList:

	List<Integer> list = new ArrayList<Integer>();
	Integer number = Integer.valueOf(42);
	for (int i = 0; i < 42; ++i)
	    list.add(number);

     If you're coming from a C background, a rough analogy is that
the ArrayList holds "pointers" to the objects it holds, not copies
of those objects.

-- 
Eric Sosman
esosman@ieee-dot-org.invalid

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Size of an arraylist in bytes sara <sarasara82@gmail.com> - 2011-11-20 13:01 -0800
  Re: Size of an arraylist in bytes markspace <-@.> - 2011-11-20 13:05 -0800
    Re: Size of an arraylist in bytes sara <sarasara82@gmail.com> - 2011-11-20 13:11 -0800
      Re: Size of an arraylist in bytes Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-11-20 21:58 +0000
      Re: Size of an arraylist in bytes markspace <-@.> - 2011-11-20 14:08 -0800
      Re: Size of an arraylist in bytes Patricia Shanahan <pats@acm.org> - 2011-11-20 14:50 -0800
      Re: Size of an arraylist in bytes Arne Vajhøj <arne@vajhoej.dk> - 2011-11-20 18:06 -0500
      Re: Size of an arraylist in bytes Lew <lewbloch@gmail.com> - 2011-11-20 20:28 -0800
  Re: Size of an arraylist in bytes Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-11-20 16:30 -0500
    Re: Size of an arraylist in bytes sara <sarasara82@gmail.com> - 2011-11-20 13:35 -0800
      Re: Size of an arraylist in bytes Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-11-20 17:19 -0500
    Re: Size of an arraylist in bytes Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-11-20 16:58 -0500
      Re: Size of an arraylist in bytes Patricia Shanahan <pats@acm.org> - 2011-11-20 14:04 -0800
        Re: Size of an arraylist in bytes Arne Vajhøj <arne@vajhoej.dk> - 2011-11-20 17:18 -0500
          Re: Size of an arraylist in bytes Patricia Shanahan <pats@acm.org> - 2011-11-20 14:48 -0800
            Re: Size of an arraylist in bytes Arne Vajhøj <arne@vajhoej.dk> - 2011-11-25 22:12 -0500
      Re: Size of an arraylist in bytes Lew <lewbloch@gmail.com> - 2011-11-20 20:44 -0800
        Re: Size of an arraylist in bytes Arne Vajhøj <arne@vajhoej.dk> - 2011-11-25 22:16 -0500
          Re: Size of an arraylist in bytes Lew <lewbloch@gmail.com> - 2011-11-25 20:15 -0800
  Re: Size of an arraylist in bytes Roedy Green <see_website@mindprod.com.invalid> - 2011-11-20 22:25 -0800
    Re: Size of an arraylist in bytes Arne Vajhøj <arne@vajhoej.dk> - 2011-11-25 22:11 -0500

csiph-web