Skip to main content
mhelyar
Visitor II
Sep 28, 2018 11:39 AM UTC
Question

Why does dynamic allocation make my program so big?

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
    Sep 28, 2018 12:00 PM UTC

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

    JW

    Bob S
    Super User
    Sep 28, 2018 3:40 PM UTC

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

    Tesla DeLorean
    Guru
    Sep 28, 2018 4:52 PM UTC

    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..