How much memory do Enums take?

后端 未结 12 1271
野性不改
野性不改 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:45

    sizeof(enum) depends upon what you have in the enum. I was recently trying to find the size of an ArrayList() with default constructor params and no objects stored inside (which means the capacity to store is 10). It turned out that ArrayList is not too big < 100 bytes.

    So, sizeof(enum) for a very simple enum should be less than 10 bytes. you can write a small program, give it a certain amount of memory and then try allocating enums. you should be able to figure it out(that's how i found out the memory of ArrayList)

    BR,
    ~A

提交回复
热议问题