Jul 11, 2019

[python] hint of reducing a bit of type instance's memory allocated

Reference:
https://habr.com/en/post/458518/
http://book.pythontips.com

Take away:
Use __slots__ if possible.
http://book.pythontips.com/en/latest/__slots__magic.html

__slots__ has been around for a while; however seldom being used in
codes, which is a good practice for limiting the fields being added to type instance dynamically during runtime.

Reason of taking less memory: it's like __slots__ vs. __dict__, which the later data structure consumes more book-keeping info then simply a continuous array.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.