Skip to content

Use of "new" compiling for Due requires 51Kb extra program memory #1485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nickgammon opened this issue Jun 24, 2013 · 1 comment
Closed
Labels
Board: Arduino Due Applies only to the Due Component: Core Related to the code for the standard Arduino API
Milestone

Comments

@nickgammon
Copy link

See forum thread: http://forum.arduino.cc/index.php?topic=173718

A small test program which uses a small class, statically allocated, compiled for the Due under 1.5.2, takes:

Binary sketch size: 9,488 bytes (of a 524,288 byte maximum) - 1% used

Changing (only) to use the "new" operator to allocate the class dynamically, the sketch now takes:

Binary sketch size: 60,776 bytes (of a 524,288 byte maximum) - 11% used

It seems excessive to take 10% of available memory just to implement the operator new.

Adding these lines to the start of the sketch:

// new
void * operator new (size_t size) { return malloc (size); }
// placement new
void * operator new (size_t size, void * ptr) { return ptr; }
// delete
void operator delete (void * ptr) { free (ptr); }

The sketch now takes:

Binary sketch size: 11,296 bytes (of a 524,288 byte maximum) - 2% used

Only 1% more memory.

There must be some linking or other problem in the way the files implementing "operator new" are constructed.

@ffissore ffissore added the New label Feb 27, 2014
@cmaglie cmaglie removed the New label Feb 27, 2014
@cmaglie cmaglie added this to the Release 1.5.8 milestone Sep 6, 2014
cmaglie added a commit that referenced this issue Sep 6, 2014
Fix #1485
A better implementation may be desirable as discussed in #108
@cmaglie
Copy link
Member

cmaglie commented Sep 6, 2014

Fixed committed 07e3e83 to be released in 1.5.8.
Thank you!

@cmaglie cmaglie closed this as completed Sep 6, 2014
ollie1400 pushed a commit to ollie1400/Arduino that referenced this issue May 2, 2022
Fix arduino#1485
A better implementation may be desirable as discussed in arduino#108
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Board: Arduino Due Applies only to the Due Component: Core Related to the code for the standard Arduino API
Projects
None yet
Development

No branches or pull requests

3 participants