Namespaces
Variants

Memory model

From cppreference.net
C++ language
General topics
Flow control
Conditional execution statements
Iteration statements (loops)
Jump statements
Functions
Function declaration
Lambda function expression
inline specifier
Dynamic exception specifications ( until C++17* )
noexcept specifier (C++11)
Exceptions
Namespaces
Types
Specifiers
constexpr (C++11)
consteval (C++20)
constinit (C++20)
Storage duration specifiers
Initialization
Expressions
Alternative representations
Literals
Boolean - Integer - Floating-point
Character - String - nullptr (C++11)
User-defined (C++11)
Utilities
Attributes (C++11)
Types
typedef declaration
Type alias declaration (C++11)
Casts
Memory allocation
Classes
Class-specific function properties
Special member functions
Templates
Miscellaneous

C++ 추상 머신의 목적을 위해 컴퓨터 메모리 저장소의 의미론을 정의합니다.

C++ 프로그램이 사용 가능한 메모리는 하나 이상의 연속적인 바이트 시퀀스입니다. 메모리의 각 바이트는 고유한 주소 를 가집니다.

목차

바이트

바이트 는 메모리의 가장 작은 주소 지정 가능 단위입니다. 이것은 충분히 큰 연속적인 비트 시퀀스로 정의되며,

  • 모든 UTF-8 코드 유닛의 값(256개의 고유한 값)과
(until C++23)
(since C++23)

C와 유사하게, C++는 8비트 이상의 크기를 갖는 바이트를 지원합니다.

타입 char , unsigned char , 그리고 signed char 는 저장과 값 표현 모두에 1바이트를 사용합니다. 한 바이트의 비트 수는 CHAR_BIT 또는 std:: numeric_limits < unsigned char > :: digits 로 접근할 수 있습니다.

메모리 위치

메모리 위치 객체 표현 이 차지하는 저장 공간으로, 스칼라 타입 의 객체 중 비트 필드 가 아닌 경우, 또는 길이가 0이 아닌 비트 필드들의 가장 큰 연속적인 시퀀스를 의미합니다.

참고: references virtual functions 와 같은 언어의 다양한 기능들은 프로그램이 접근할 수 없지만 구현에 의해 관리되는 추가적인 메모리 위치를 포함할 수 있습니다.

struct S
{
    char a;     // 메모리 위치 #1
    int b : 5;  // 메모리 위치 #2
    int c : 11, // 메모리 위치 #2 (계속)
          : 0,
        d : 8;  // 메모리 위치 #3
    struct
    {
        int ee : 8; // 메모리 위치 #4
    } e;
} obj; // 객체 "obj"는 4개의 별도 메모리 위치로 구성됨

결함 보고서

다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.

DR 적용 대상 게시된 동작 올바른 동작
CWG 1953 C++98 동일한 저장 공간을 점유하는 객체들은
서로 다른 메모리 위치로 간주됨
메모리 위치가
이제 저장 공간을 참조함

참고 항목

C 문서 참조: 메모리 모델