473,396 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

ArrayList size of elements

Does anyone know how the ArrayList works in regards to sizing of
elements? What I mean is if you add 1,000 byte values to an
ArrayList does that mean that the ArrayList is then 1,000 bytes long
- or does it store each byte as a generic "object" - thus storing it
as a 4 bytes each??
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 15 '05 #1
4 3960
NoLongerMicah <pj**********@ra.rockwell-dot-com.no-spam.invalid> wrote:
Does anyone know how the ArrayList works in regards to sizing of
elements? What I mean is if you add 1,000 byte values to an
ArrayList does that mean that the ArrayList is then 1,000 bytes long
- or does it store each byte as a generic "object" - thus storing it
as a 4 bytes each??


Actually, you'd end up taking more than that - 4 bytes for the actual
value, 8 bytes (IIRC) object overhead, and 4 bytes for the reference in
the ArrayList. Basically, you don't want to be doing that...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
To answer my own question - the byte value is "boxed" - therefore for
each byte you add an "object" and a "byte" to the heap (the "object"
is a reference to the "byte" value).

So an array instance of 1,000 "bytes" would occupy 5,000 bytes on the
heap.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 15 '05 #3
Thanks for the clarification. I wasn't thinking - didn't realize that
they store the byte as a object as well as it's reference as an
object.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 15 '05 #4
NoLongerMicah <pj**********@ra.rockwell-dot-com.no-spam.invalid> wrote:
To answer my own question - the byte value is "boxed" - therefore for
each byte you add an "object" and a "byte" to the heap (the "object"
is a reference to the "byte" value).

So an array instance of 1,000 "bytes" would occupy 5,000 bytes on the
heap.


You're assuming that the cost of an object is 4 bytes, and that the
byte can be stored on its own - what makes you think that? Each object
has an 8 byte header, and I believe the data itself is stored in 4 byte
blocks, so 1000 boxed bytes would actually take 12K of heap. That's
consistent with a short test program, too.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tristan | last post by:
Hi, My code reads through a file of shapes adding each one to an ArrayList as it does so. The problem is that for files with large numbers of shapes, calling ArrayList.Add(MyShape) is...
9
by: Davids | last post by:
is it true that I cannot dynamically add an item to an array? Eg public char = {"a","b"}; char.Add("newitem"); Do I really have to switch to ArrayList to do this?
2
by: Jason Reis | last post by:
I need to keep track of up to 100 values. When the list reaches 100, I'd like the first to be removed and the new item added to the end. My first thought was the Stack class, but I need to be...
4
by: Peter | last post by:
I run into this situation all the time and I'm wondering what is the most efficient way to handle this issue: I'll be pulling data out of a data source and want to load the data into an array so...
5
by: Paul | last post by:
Off the cuff, does anyone know if arraylist is more efficeint at adding items to an array than redim preserve? Paul <begin loop> Dim c As Integer = SomeArray.GetUpperBound(0) + 1 ReDim...
18
by: Sam | last post by:
Hi All I'm planing to write an application which allows users dynamically add their points (say you can add upto 30,000) and then draw xy graph. Should I use an array for my coordinate point...
7
by: heavyone | last post by:
I am trying to write a removeFirst method for an ArrayList of the generic type. The removeFirst method is supposed to do a few things: 1) If the list is empty it throws an error. 2) It stores the...
3
by: rn5a | last post by:
What's wrong with the following code? Dim arrColors(5) As ArrayList arrColors(5) = New ArrayList arrColors(0).Add("Red") arrColors(1).Add("Blue") arrColors(2).Add("Green")...
8
by: scottc | last post by:
i'm stuck and i need a little direction. i'm only getting 2 error messages. i have 2 files: import java.util.ArrayList; import java.util.*; //author public class StudentTester { ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.