By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,366 Members | 1,364 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,366 IT Pros & Developers. It's quick & easy.

Removing array entry so cumbersome??

P: n/a
Is there a direct way to remove one entry from a one dimensional array?

I keep looking but either my eyes are funny or it isn't there.

Must we really create a temp array and copy all but 1 of the entries over to
delete one entry?

All I want to do is remove an entry at a specified index and then have the
ubound(array) go down -1.

Thanks in advance,
Adam
May 7 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Why not use an ArrayList in the collections namespace, this already has the
member functions to do this.
--
( OHM ) - One Handed Man
AKA Terry Burns - http://TrainingOn.net
"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> wrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Is there a direct way to remove one entry from a one dimensional array?

I keep looking but either my eyes are funny or it isn't there.

Must we really create a temp array and copy all but 1 of the entries over
to delete one entry?

All I want to do is remove an entry at a specified index and then have the
ubound(array) go down -1.

Thanks in advance,
Adam

May 7 '06 #2

P: n/a
"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> schrieb:
Is there a direct way to remove one entry from a one dimensional array?

I keep looking but either my eyes are funny or it isn't there.

Must we really create a temp array and copy all but 1 of the entries over
to delete one entry?


Arrays are somewhat static data structures. If you have to add, insert, and
remove items often, you'd better use a dynamic data structure like
'ArrayList' or 'List(Of T)' in VB 2005.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

May 7 '06 #3

P: n/a
How is an arraylist organized in memory. I know an array is simply like
building blocks stacked one after the other. Does an arraylist use pointers
to various memory locations where the blocks are scattered around throughout
memory?
--
Dennis in Houston
"Herfried K. Wagner [MVP]" wrote:
"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> schrieb:
Is there a direct way to remove one entry from a one dimensional array?

I keep looking but either my eyes are funny or it isn't there.

Must we really create a temp array and copy all but 1 of the entries over
to delete one entry?


Arrays are somewhat static data structures. If you have to add, insert, and
remove items often, you'd better use a dynamic data structure like
'ArrayList' or 'List(Of T)' in VB 2005.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

May 9 '06 #4

P: n/a

Dennis wrote:
How is an arraylist organized in memory. I know an array is simply like
building blocks stacked one after the other. Does an arraylist use pointers
to various memory locations where the blocks are scattered around throughout
memory?


Internally an ArrayList holds its members in an array. The point is
that it manages addition and removal for you.

--
Larry Lard
Replies to group please

May 10 '06 #5

P: n/a
If that's the case, then there is really no "speed advantage" except for any
optimizatin that M'soft does in the ArrayList Class. Then there is one point
that bothers me and that's the way I understand the arraylist works. For
example, it starts out with 16 elements when a New Arraylist is declared.
When you try to set the 17th element, the arraylist doubles in size to 32 and
so on. So, for example, if you have set the 40,000th element and that
happens to trigger an expansion of the array pointed to by the arraylist,
then you will end up with 80,000 elements. This would end up with an 80,000
element array storage, abiet only with pointers to a nothing object. If I
use the redim on an array when it gets full, I probably would end up with a
lot less array elements in the end. Is this correct?
--
Dennis in Houston
"Larry Lard" wrote:

Dennis wrote:
How is an arraylist organized in memory. I know an array is simply like
building blocks stacked one after the other. Does an arraylist use pointers
to various memory locations where the blocks are scattered around throughout
memory?


Internally an ArrayList holds its members in an array. The point is
that it manages addition and removal for you.

--
Larry Lard
Replies to group please

May 10 '06 #6

P: n/a
On Tue, 9 May 2006 16:21:01 -0700, Dennis
<De****@discussions.microsoft.com> wrote:
If that's the case, then there is really no "speed advantage" except for any
optimizatin that M'soft does in the ArrayList Class. Then there is one point
that bothers me and that's the way I understand the arraylist works. For
example, it starts out with 16 elements when a New Arraylist is declared.
When you try to set the 17th element, the arraylist doubles in size to 32 and
so on. So, for example, if you have set the 40,000th element and that
happens to trigger an expansion of the array pointed to by the arraylist,
then you will end up with 80,000 elements. This would end up with an 80,000
element array storage, abiet only with pointers to a nothing object. If I
use the redim on an array when it gets full, I probably would end up with a
lot less array elements in the end. Is this correct?


The ArrayList works very fast for adding elements as it doesn't need to
resize the array ever time it adds a new element. If you have an array
with 40,000 elements in it and it runs out of space, in all likeliness
you are going to want a large array as you are storing a lot.

If you have just finished some sort of bulk insert and want to compact
the array you could use ArrayList.TrimToSize() which reduces the size of
the array to the size of the data it stores.

As for speed improvments, and the copying issue on removing an item (or
inserting in the middle of an array). There is no way round that, this
is a limitation of an array.
May 10 '06 #7

P: n/a

Dennis wrote:
If that's the case, then there is really no "speed advantage" except for any
optimizatin that M'soft does in the ArrayList Class.
The point of an ArrayList isn't a speed advantage - the point is that
it encapsulates the details for you, so you can use it as a list.

There's nothing in the collection classes that does any magic
optimization. The speed advantage comes in not having to write the code
yourself.
Then there is one point
that bothers me and that's the way I understand the arraylist works. For
example, it starts out with 16 elements when a New Arraylist is declared.
When you try to set the 17th element, the arraylist doubles in size to 32 and
so on. So, for example, if you have set the 40,000th element and that
happens to trigger an expansion of the array pointed to by the arraylist,
then you will end up with 80,000 elements. This would end up with an 80,000
element array storage, abiet only with pointers to a nothing object. If I
use the redim on an array when it gets full, I probably would end up with a
lot less array elements in the end. Is this correct?


You can use TrimToSize to make an ArrayList trim its array down to the
size of the list.

--
Larry Lard
Replies to group please

May 10 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.