Misra c++, 동적할당 금지.
6.18.4 Dynamic memory management
Rule 18–4–1 (Required)
Dynamic heap memory allocation shall not be used.
Rationale The use of dynamic memory can lead to out-of-storage run-time failures, which are undesirable.
The built-in new and delete operators, other than the placement versions, use dynamic heap
memory. The functions calloc, malloc, realloc and free also use dynamic heap memory.
There is a range of unspecified, undefined and implementation-defined behaviour associated with dynamic memory allocation, as well as a number of other potential pitfalls. Dynamic heap memory allocation may lead to memory leaks, data inconsistency, memory exhaustion, non-deterministic behaviour, etc.
Note that some implementations may use dynamic heap memory allocation to implement other
functions (for example, functions in the library cstring). If this is the case, then these functions shall also be avoided.
Example
void f1 ( )
{
int32_t * i = new int32_t;
// Non-compliant
delete i;
}
==============================================================================
Misra C++ 코딩 룰에 보면 new / malloc 과 같은 동적할당을 못 하게 하는데요.
동적 할당 안 하고 어떻게 쓰라는 건지... 감 좀 잡게 도와주실 분 계신가요?
int32_t i;
int32_t* x = &i;
이건 알겠는데요.
일반적으로 new를 안 쓰고 프로그래밍이 가능한가요?
질문이 너무 두리뭉실해서 죄송합니다.
placement new 를 쓰라고 대놓고 본문에서
placement new 를 쓰라고 대놓고 본문에서 지적을 하잖아요.
댓글 달기