ArrayList vs Arrays - Performance

G

Guest

I wish to build up a byte array from various sources of different lengths. I
can either use a byte array and redimension it as needed as I add the various
values or use an arraylist which automatically expands as required then
convert it to an array after I finish adding the elements. Does anyone know
which would be faster considering that I would probably have about 10 redim
statements if I use a byte array. Microsoft's literature suggests using an
arraylist would be better but I don't always trust M'soft.
 
M

Mattias Sjögren

Dennis,
Does anyone know
which would be faster considering that I would probably have about 10 redim
statements if I use a byte array.

Can't you allocate a byte array that is larger than you initially
need, to reduce the number of ReDims?

I'd avoid ArrayList when working with bytes due to the boxing
overhead.



Mattias
 
G

Guest

What is "boxing overhead"?

Mattias Sjögren said:
Dennis,


Can't you allocate a byte array that is larger than you initially
need, to reduce the number of ReDims?

I'd avoid ArrayList when working with bytes due to the boxing
overhead.



Mattias
 
C

Cor Ligthert

Dennis,
Microsoft's literature suggests using an arraylist would be better
but I don't always trust M'soft.

Why do you have doubts in the case of the arraylist.

It is a list that adds a reference against redimmension a complete array.

When you have doubts about that than you would start in my opinion as well
checking if a multiply operator is faster than a repeated add.

Just my thought,

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top