pointers and lists

Just starting out? Need help? Post your questions and find answers here.
jerico2day
User
User
Posts: 37
Joined: Mon Jul 13, 2009 5:41 pm

pointers and lists

Post by jerico2day »

Hey all, I'm designing something using pointers to keep track of list items for speed reasons. I'm wondering if a pointers address will ever change in a list element? I've done some tests where I added and deleted elements and no other elements changed their pointer address, but I want to make sure this is actually the case over the runtime of a program.
User avatar
Demivec
Addict
Addict
Posts: 4281
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: pointers and lists

Post by Demivec »

jerico2day wrote:Hey all, I'm designing something using pointers to keep track of list items for speed reasons. I'm wondering if a pointers address will ever change in a list element? I've done some tests where I added and deleted elements and no other elements changed their pointer address, but I want to make sure this is actually the case over the runtime of a program.
List elements won't ever change addresses once they are added. So, unless you delete them and add them back they'll always be at the same address.
User avatar
STARGÅTE
Addict
Addict
Posts: 2260
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: pointers and lists

Post by STARGÅTE »

You are right, an element remains as long as it exists its address!

This is different from the array to be increased with ReDim, hheir field-addresses can change, if the array is larger.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
Demivec
Addict
Addict
Posts: 4281
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: pointers and lists

Post by Demivec »

@jerico2day: One additional note, you can also sort the elements in a Linked-List (or otherwise reorder them) and they will still be at the same addresses because only an element's links are changed and not its address.
jerico2day
User
User
Posts: 37
Joined: Mon Jul 13, 2009 5:41 pm

Re: pointers and lists

Post by jerico2day »

Great, thanks guys!
Post Reply