Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #10138
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Size of an arraylist in bytes |
| Date | 2011-11-20 22:25 -0800 |
| Organization | Canadian Mind Products |
| Message-ID | <7erjc7djbkc4b7pdd2rr12qjelhm1ll76h@4ax.com> (permalink) |
| References | <e9dcfb2d-dfef-4ae6-9d9f-979a8f08b962@t36g2000prt.googlegroups.com> |
On Sun, 20 Nov 2011 13:01:44 -0800 (PST), sara <sarasara82@gmail.com> wrote, quoted or indirectly quoted someone who said : >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? What code did you use to convert to byte[]? An ArrayList consists of a base ArrayList object, a array of pointers object, and one object for each integer. If the integers are small, e.g. two 1s in the list will point to the same canonical Integer object. Each object (including all the Integers) has perhaps 8 to 16 bytes of overhead. So it is fairly complicated to figure out how much RAM this thing uses. It is not like a C array where you just multiply 4xslots. An int[] is much simpler. -- Roedy Green Canadian Mind Products http://mindprod.com I can't come to bed just yet. Somebody is wrong on the Internet.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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