Difference between revisions of "cpp/language/memory model"
(spanish link) |
(Removed the [intro.multithread] content, they are now in a new page.) |
||
(14 intermediate revisions by 9 users not shown) | |||
Line 6: | Line 6: | ||
===Byte=== | ===Byte=== | ||
− | A ''byte'' is the smallest addressable unit of memory. It is defined as a contiguous sequence of bits, large enough to hold | + | A ''byte'' is the smallest addressable unit of memory. It is defined as a contiguous sequence of bits, large enough to hold |
+ | * the value of any {{tt|UTF-8}} code unit (256 distinct values) and of | ||
+ | {{rrev multi | ||
+ | |rev1= | ||
+ | * any member of the {{rlpsd|charset#Basic execution character set}}. | ||
+ | |since2=c++23|rev2= | ||
+ | * the ordinary literal encoding of any element of the {{rlpsd|charset#Basic literal character set}}. | ||
+ | }} | ||
+ | Similar to C, C++ supports bytes of sizes 8 bits and greater. | ||
− | The {{rlp|types}} {{c|char}}, {{c|unsigned char}}, and {{c|signed char}} use one byte for both storage and {{rlp|object|value representation}}. The number of bits in a byte is accessible as {{lc|CHAR_BIT}} or {{c|std::numeric_limits<unsigned char>::digits}}. | + | The {{rlp|types}} {{c/core|char}}, {{c/core|unsigned char}}, and {{c/core|signed char}} use one byte for both storage and {{rlp|object|value representation}}. The number of bits in a byte is accessible as {{lc|CHAR_BIT}} or {{c|std::numeric_limits<unsigned char>::digits}}. |
===Memory location=== | ===Memory location=== | ||
A ''memory location'' is | A ''memory location'' is | ||
− | * an object of {{rlp|type|scalar type}} | + | * an object of {{rlp|type|scalar type}}, or |
− | * | + | * the largest contiguous sequence of {{rlp|bit field|bit-fields}} of non-zero length. |
Note: Various features of the language, such as {{rlp|reference|references}} and {{rlp|virtual|virtual functions}}, might involve additional memory locations that are not accessible to programs but are managed by the implementation. | Note: Various features of the language, such as {{rlp|reference|references}} and {{rlp|virtual|virtual functions}}, might involve additional memory locations that are not accessible to programs but are managed by the implementation. | ||
{{source| | {{source| | ||
− | struct S { | + | struct S |
+ | { | ||
char a; // memory location #1 | char a; // memory location #1 | ||
int b : 5; // memory location #2 | int b : 5; // memory location #2 | ||
Line 24: | Line 33: | ||
: 0, | : 0, | ||
d : 8; // memory location #3 | d : 8; // memory location #3 | ||
− | struct { | + | struct |
+ | { | ||
int ee : 8; // memory location #4 | int ee : 8; // memory location #4 | ||
} e; | } e; | ||
− | } obj; // The object | + | } obj; // The object “obj” consists of 4 separate memory locations |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
}} | }} | ||
− | |||
===See also=== | ===See also=== | ||
{{dsc begin}} | {{dsc begin}} | ||
− | {{dsc see c | c/language/ | + | {{dsc see c|c/language/memory model|Memory model|nomono=true}} |
{{dsc end}} | {{dsc end}} | ||
− | {{langlinks|es|zh}} | + | {{langlinks|es|ja|ru|zh}} |
Latest revision as of 22:47, 21 April 2024
Defines the semantics of computer memory storage for the purpose of the C++ abstract machine.
The memory available to a C++ program is one or more contiguous sequences of bytes. Each byte in memory has a unique address.
[edit] Byte
A byte is the smallest addressable unit of memory. It is defined as a contiguous sequence of bits, large enough to hold
- the value of any
UTF-8
code unit (256 distinct values) and of
|
(until C++23) |
|
(since C++23) |
Similar to C, C++ supports bytes of sizes 8 bits and greater.
The types char, unsigned char, and signed char use one byte for both storage and value representation. The number of bits in a byte is accessible as CHAR_BIT or std::numeric_limits<unsigned char>::digits.
[edit] Memory location
A memory location is
- an object of scalar type, or
- the largest contiguous sequence of bit-fields of non-zero length.
Note: Various features of the language, such as references and virtual functions, might involve additional memory locations that are not accessible to programs but are managed by the implementation.
struct S { char a; // memory location #1 int b : 5; // memory location #2 int c : 11, // memory location #2 (continued) : 0, d : 8; // memory location #3 struct { int ee : 8; // memory location #4 } e; } obj; // The object “obj” consists of 4 separate memory locations
[edit] See also
C documentation for Memory model
|