ID:2120407
 
(See the best response by Kaiochao.)
is it possible to initialize Lists like or do I need to manually overload the list New proc?? or just not mess with it
var/list/L=new(1,2,3,4);

also which is faster
mob/verb/A()
var/list/L=new(1,2,3,4);
var/x=L[1]+L[2]+L[3]+L[4]

or
Storage
var/a,b,c,d
New(A,B,C,D)
a=A,b=B,c=C,d=D

mob/verb/A()
var/Storage/L=new(1,2,3,4);
var/x=L[1]+L[2]+L[3]+L[4]

I mean use a datum or a list as storage for 4 integer numbers? I'm gonna pass them through procs a lot of times so I need the fastest way to pass the data and also extract the vars inside them.
Best response
You need to use the list() proc, not new /list ().

The difference is that list(x, y, z) is a list initialized with x, y, and z inside, but new/list(x, y, z) is a 3D list that contains x lists that contain y lists that contain z nulls.

A list is always going to be faster to initialize than an equivalent datum, but a datum is often more appropriate because of object oriented programming.

You might not have to always create a new list or datum, though, if you use object pooling.
What do you mean object pooling like store all the data in one object??

Thanks for the list proc

btw just tested it and the accessing the datum vars was faster by 30% while creating datums was 300% slower so I guess I can just create a datum and use it as storage creation will take more but I will benefit from faster access
In response to Victorqr
I mean object pooling as in most of the first page of Google results when you search "object pooling".

Basically, create as many objects as you predict you'll ever need, all at once. When you want a fresh instance, take one from the pool. When you're done with it, put it back in the pool and reset its state. The result is less memory allocation due to instantiating new objects. Allocating memory is expensive, so you should make it happen less often.
ohh I got it thanks I used that though for my projectiles but didn't know it had its own name :)

Thanks for the help :)