How much memory do Enums take?

后端 未结 12 1280
野性不改
野性不改 2020-12-13 06:13

For example if I have an Enum with two cases, does it make take more memory than a boolean? Languages: Java, C++

12条回答
  •  南笙
    南笙 (楼主)
    2020-12-13 06:40

    You would only worry about this when storing large quantities of enums. For Java, you may be able to use an EnumSet in some cases. It uses a bit vector internally which is very space efficient and fast.

    http://java.sun.com/j2se/1.5.0/docs/api/java/util/EnumSet.html

提交回复
热议问题