I have an object that represents a User
and a variable measured 20 times. The object will be something like this:
class User:
user_id: str
measures: List[float] #this is a list(or an array) of size 20
Given that I have many users that I need to represent I would like to use __slots__
to store the variable (so I can save space). Although I don't know if it's possible to implement this directly will save memory, because it probably will store the memory for the pointer to the list, but not the list floats. The following code runs, but not sure how is memory-wise compared to the latter:
class User:
__slots__ =['user_id', 'measures'] # this implementation runs, but no idea if its using slots "properly"
user_id: str
measures: List[float]
def __init__(self, user_id:str, measures:List[float]):
#...
or maybe the only alternative is to declare the 20 variables independently? (this is very cumbersome but I know it will work)
class User:
__slots__ =['user_id', 'm1', 'm2', ...] #very cumbersome
user_id: str
m1:float
m2:float
...
def __init__(self, user_id:str, measures:List[float]):
#...
or maybe I should use another class that contains the measures
.