Skip to main content
mhelyar
Visitor II
September 28, 2018
Question

Why does dynamic allocation make my program so big?

  • September 28, 2018
  • 3 replies
  • 715 views

Before you say it, I know dynamic allocation is usually a bad idea with embedded software, this is more of a technical question.

If I create a new blank C++ project based on my Nucleo-L152RE in SW4STM32, the "text" portion of my compiled project read by the "size" command is about 1kB. If I then add the lines:

	int* p = new int;
	delete p;

text size becomes 75kB. data and BSS are basically unaffected.

Why is it so?

    This topic has been closed for replies.

    3 replies

    waclawek.jan
    Super User
    September 28, 2018

    .text is code, so it's the libraries pulled in. Look at the mapfile.

    JW

    Bob S
    Super User
    September 28, 2018

    Perhaps new pulls in exception handling code? As Jan said, check the map file.

    Tesla DeLorean
    Guru
    September 28, 2018

    and frankly pulling in anything the constructors/destructors touch or are dependent on

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..