변수 type별 memory allocation
일반적으로
정수형
- short : 2bytes
- int : 4bytes
- long : 8bytes
실수형 - float : 4bytes
- double : 8bytes
로 사용한다.
c++ 스탠다드에 따르면 int는 at least 16bits로 되어있어 컴파일러나 아키텍처에 따라 2bytes일 수도 있다.
이를 해결하기 위해
- 조건이 맞는지 확인해주는 static_assertion(sizeof(int)==4)을 사용하여 확인해준다.
- c++ 스탠다드의 Fixed width integer types를 이용한다
#include <cstdint>
~~~
cout << sizeof(int8_t) << "\n";
cout << sizeof(int64_t) << "\n";
는
1bytes
8bytes를 리턴한다
c++에서 array를 사용할때는 array std를 사용하는 것이 좋은데
array<uint64_t,5> arr;
같은 식으로 변수 type과 arr의 크기를 지정할 수 있기 때문이다.
% vector std를 안쓰는경우
- 힙 메모리 allocation deallocation에 시간이 소모되어 이를 줄여야 할 경우
- 메모리 단편화(fragment)가 없어야할 경우
Author And Source
이 문제에 관하여(변수 type별 memory allocation), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@dik654/변수-type별-memory-allocation저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)