If not even one byte is allocated in the memory, then naturally there is no memory address that can represent this object, but even if only one byte is allocated, this object can be guaranteed to be allocated to a unique address.
Please refer to this link: http://stackoverflow.com/questions/2362097/why-is-the-size-of-an-empty-class-in-c-not-zero
C++The standard does not allow a class that occupies 0 memory, because if there is such a class, two different class objects may occupy the same memory address.
The standard in C++ stipulates that the smallest object, including native types char/int, etc., has a minimum value of 1. It is mainly used to distinguish different objects. Just imagine what you would do if the new thing does not occupy memory? Furthermore, if the address of your empty class is 0, then it stands to reason that the size of the array of the empty class is also 0? This is obviously a paradox
This is because the minimum addressing unit of memory is 1 byte. In other words, 8bit is a whole, which is the smallest unit for memory operations. 8bit is a byte. Because the smallest unit of an integer is 1, and the memory address is an integer, each byte in the memory has a unique integer to represent its memory address. That is, the address of each byte is unique. Note: The above remarks are just simple explanations of the problem and are not rigorous. There is no explanation of multi-processing, virtual addresses, etc.
The question needs to be re-explained. There is no magic here, classes are templates that generate objects, and objects must have a size to be allocated in memory, so giving 1 byte or multiple bytes has the same effect.
It just allocates memory. 1 byte is the minimum allocation unit. You can allocate 2, 3, or 4 bytes, but it is a waste of memory. So the program compiled by the compiler will only allocate the minimum memory. , which is 1 byte
As for 独一无二, the memory address is of course unique. If the two memory addresses are the same, then how to read and write them? Memory operations are all performed through addresses The address is their ID (the only certain ID card), so it’s good to understand it
If not even one byte is allocated in the memory, then naturally there is no memory address that can represent this object, but even if only one byte is allocated, this object can be guaranteed to be allocated to a unique address.
Please refer to this link: http://stackoverflow.com/questions/2362097/why-is-the-size-of-an-empty-class-in-c-not-zero
C++
The standard does not allow a class that occupies 0 memory, because if there is such a class, two different class objects may occupy the same memory address.The standard in C++ stipulates that the smallest object, including native types char/int, etc., has a minimum value of 1. It is mainly used to distinguish different objects. Just imagine what you would do if the new thing does not occupy memory? Furthermore, if the address of your empty class is 0, then it stands to reason that the size of the array of the empty class is also 0? This is obviously a paradox
This is because the minimum addressing unit of memory is 1 byte.
In other words, 8bit is a whole, which is the smallest unit for memory operations. 8bit is a byte.
Because the smallest unit of an integer is 1, and the memory address is an integer, each byte in the memory has a unique integer to represent its memory address. That is, the address of each byte is unique.
Note: The above remarks are just simple explanations of the problem and are not rigorous. There is no explanation of multi-processing, virtual addresses, etc.
The question needs to be re-explained. There is no magic here, classes are templates that generate objects, and objects must have a size to be allocated in memory, so giving 1 byte or multiple bytes has the same effect.
In order to distinguish the addresses of two different objects
It just allocates memory. 1 byte is the minimum allocation unit. You can allocate 2, 3, or 4 bytes, but it is a waste of memory.
So the program compiled by the compiler will only allocate the minimum memory. , which is 1 byte
As for
独一无二
, the memory address is of course unique. If the two memory addresses are the same,then how to read and write them? Memory operations are all performed through addresses
The address is their ID (the only certain ID card), so it’s good to understand it
You allocate 1 byte of memory, this is the only memory of the machine