Does an element within a linked list/map keep its address forever?

Everything else that doesn't fall into one of the other PB categories.
User avatar
jacdelad
Addict
Addict
Posts: 2010
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Does an element within a linked list/map keep its address forever?

Post by jacdelad »

Hello,
when I get the address of an element within a linked list or map, does the address to this element always stay the same (as long as I don't use MergeList(), CopyList(), etc.)?
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
Demivec
Addict
Addict
Posts: 4269
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Does an element within a linked list/map keep its address forever?

Post by Demivec »

Yes linked-list elements will remain at the same address. It should be safe even after MergeList() also. Only links are changed when rearranging list elements not the addresses of the elements. That's why they are called 'linked' lists.


Map elements may change.





@Edit: My first response ignored Map elements.
Last edited by Demivec on Sat Aug 20, 2022 2:06 pm, edited 1 time in total.
User avatar
jacdelad
Addict
Addict
Posts: 2010
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Does an element within a linked list/map keep its address forever?

Post by jacdelad »

Yeah, that's what I suspected, thanks.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
idle
Always Here
Always Here
Posts: 5901
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Does an element within a linked list/map keep its address forever?

Post by idle »

map elements may change if it resizes.
Post Reply