ID:2267377
 
(See the best response by Ter13.)
So basically I have more of a question, using the above operators on a list wherein we wish to prevent duplicates, do we use .Add, += or |= ? Also what would be the fastest/best performing way to add/remove things from a list?

I hope someone gets my question, thanks in advance!
|= to prevent duplicates.

+= and .Add are about equally as fast as one another.

|= is slower, because it has to search the list for duplicates before adding one.
About as equally, meaning there is a faster one?

Aaand for removal, people have said that using list.len = 0 rather than list.Cut() is better and less laggy since it uses the garbage collector, any chance you could explain that to me?
Best response
No, += and .Add are basically as fast as you can get adding things to a list.

list.Cut() returns a list of the elements cut from the list.

Assigning the length to zero simply truncates the list, causing everything in it to be dereferenced.

If you don't actually need to hang on to the contents of the list, and want to empty it while hanging on to the list itself, assigning the length to 0 is better.

As for the garbage collector comment, some SS13 folk have indicated that they are having memory leak problems with lists. I haven't observed it in action enough to rule out something in the works of their code interfering with garbage collection.

What I can say is that in nearly every case I've investigated memory leaks, I've found the vast majority of them to be caused inadvertently by the programmer, and not a flaw with BYOND. That said, I've found a few in the past as well that were problems with BYOND.
Awesome, sounds like the idea I had of how that worked was pretty on point. would it be advisable however to use list.len = 0 on for example resetting overlays?
I'm not 100% sure you can set the overlays list's length like that. Though lum made some changes to it recently, so I can't say for sure whether you can or can't.

Same thing with contents. Overlays, underlays, and contents are special lists that aren't really lists, so how they work is a little odd sometimes.
list[key] = value is o(log 2 n), where n is the length of the list.

It's faster than |=, slower than list[index] = value, and in most cases, it's slower than l += item/l.Add(item).


When lists hit a certain size, they try to allocate a new memory block to keep its memory in a single run. This is called reallocation. key-value pairs are stored in a red-black tree, which is a binary optimization that allows quick reading of data by reducing the number of nodes it has to search by storing them in a branching structure.

But yeah, key-value storage is a good way to prevent duplicates too.
Would anyone else know if you can nullify (garbage collect) overlays and/or underlays and how it could affect (or break) the game?