C, Embedded C ++ 또는 전체 C ++을 사용한 "Hello World"의 크기 비교

기술노트 11872

아키텍처:

ARM

컴포넌트:

compiler

업데이트:

2018-02-28 오전 1:47

Introduction

There exists a 'truth' that states 'output based on C++ source is much, much larger than output based on C source'.

It is of course true that the output is somewhat larger, but there are also strong reasons for using one of the C++ dialects.

How much memory will be used?

To compare the basic consumption of memory we have written a 'Hello World' project in all available dialects of C and C++ (using IAR Embedded Workbench for ARM version 6.xx). Download the project here.

The result looks like:

- - - C - - -

  • Compiler : ICCARM 6.10.3 
  • Language : C 
  • C dialect : C89 / C99 
  • Language conformance : Standard with IAR extensions 
  • Optimizations : Low 
  • Library Configuration : Normal 
  • printf/scanf formatters : Full 
  • // Hello World - Plain C
    #include <stdio.h>

    int main (void)
    {
    printf ("Hello World\n");

    return (0);
    } 

    8 858 bytes of readonly code memory
    54 bytes of readonly data memory
    8 712 bytes of readwrite data memory

- - - Embedded C++ - - -

  • Compiler : ICCARM 6.10.3 
  • Language : C++ 
  • C++ dialect : Embedded C++ / Extended Embedded C++ 
  • Language conformance : Standard with IAR extensions 
  • Optimizations : Low 
  • Library Configuration : Normal 
  • printf/scanf formatters : Full 
  • // Hello World - Embedded C++
    #include <iostream>

    int main (void)
    {
    cout << "Hello World" << endl;

    return (0);
    }

    8 928 bytes of readonly code memory
    252 bytes of readonly data memory
    42 644 bytes of readwrite data memory

- - - Full C++ - - -

  • Compiler : ICCARM 6.10.3 
  • Language : C++ 
  • C++ dialect : C++ (With exceptions, With RTTI) 
  • Language conformance : Standard with IAR extensions
  • Optimizations : Low
  • Library Configuration : Normal
  • printf/scanf formatters : Full
  • //Hello World - Full C++ with exceptions
    #include <iostream>

    using namespace std;

    int main (void)
    {
    try
    {
    cout << "Hello World" << endl;
    }
    catch (...)
    {
    cout << "Exception happened" << endl;
    }
    return (0);
    }

    21 963 bytes of readonly code memory
    2 637 bytes of readonly data memory
    42 680 bytes of readwrite data memory

Summary

Hello World - Plain C

8 858 bytes of readonly code memory
54 bytes of readonly data memory
8 712 bytes of readwrite data memory

Hello World - Embedded C++

8 928 bytes of readonly code memory
252 bytes of readonly data memory
42 644 bytes of readwrite data memory

Hello World - Full C++ with exceptions

21 963 bytes of readonly code memory
2 637 bytes of readonly data memory
42 680 bytes of readwrite data memory

 All product names are trademarks or registered trademarks of their respective owners.

죄송하지만, 당사 사이트에서는 Internet Explorer를 지원하지 않습니다.보다 편안한 사이트를 위해 Chrome, Edge, Firefox 등과 같은 최신 브라우저를 사용해 주시길 부탁드립니다.