WiringProject / Wiring

Wiring Framework
http://wiring.org.co/
Other
217 stars 168 forks source link

Standard conformant operator new and operator delete #21

Open kibergus opened 12 years ago

kibergus commented 12 years ago

Please make implementations of these operator standard conformant. Those variants of new, which are already present in wiring library must check return value of malloc and, in case of memory allocation error call std::terminate. The reason is that nobody checks return value of new because it always returns valid address. So if you return 0 the firmware would crash badly because of memory corruption. If programmer wants to check for address returned by new, he must call nothrow version of new which should be provided by the library. There is also placement new, which is a must have tool for writing containers, such as circular buffer.

You can find correct implementation of them in uClibc++ https://github.com/kibergus/StandardCplusplus

Some additional information, why terminating program from new is a good solution is here: http://kibergus.su/en/node/92

Thanks.