프로그래밍 퀴즈 – 스택 할당과 힙 할당

  • Post author:
  • Post category:칼럼
  • Post comments:0 Comments
  • Post last modified:January 25, 2016

질문

동일한 역할을 하는 C++ 코드가 두 개 있다. 아래 코드를 보고 문제점을 찾아내고 어느 쪽을 선호하는지, 그 이유는 무엇인지 설명하라.

// C++
void reserve(const Bus& bus)
{
    wchar_t buf[100];
    len = swprintf( buf, 100, L"%s", bus.name() );
    assert(len > 0 );
    
    // 중략
}
// C++
void reserve(const Bus& bus)
{
    wchar_t buf = new wchar_t[100];
    len = swprintf( buf, 100, L"%s", bus.name() );
    assert(len > 0 );
    
    // 중략
    delete buf;
}
Author Details
Kubernetes, DevSecOps, AWS, 클라우드 보안, 클라우드 비용관리, SaaS 의 활용과 내재화 등 소프트웨어 개발 전반에 도움이 필요하다면 도움을 요청하세요. 지인이라면 가볍게 도와드리겠습니다. 전문적인 도움이 필요하다면 저의 현업에 방해가 되지 않는 선에서 협의가능합니다.
0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments