在python中存储布尔值以节省内存的最佳方法 [英] Best way to store boolean values to save memory in python

查看:30
本文介绍了在python中存储布尔值以节省内存的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在字典中存储 100 万到 450,000 个布尔值的最佳方式是什么?我需要使用尽可能少的内存.True 和 Int 每个条目都占用超过 22 个字节.每个布尔值是否存在较低的内存?

What is the best way to store between a million to 450,000 Boolean values in a dictionary like collection indexed by a long number? I need to use the least amount of memory possible. True and Int both take up more than 22 bytes per entry. Is there a lower memory per Boolean possible?

推荐答案

查看这个问题.Bitarray 似乎是首选.

这篇关于在python中存储布尔值以节省内存的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆