For write-only purposes, zeroing bits in an object will not affect the invocation of the calling destructor (unless the compiler has a special quirk that allows this behavior). Just write some registry statements in your destructor to verify this.
Structuring your program so as not to highlight anything is probably a way to develop a system. I didn’t work with embedded systems before, however I read some experienced built-in stores that prevent the use of dynamic memory, because the runtime has its drawbacks.
However, if necessary, you can still use the new placement. If you don't have a <new> header, here are the relevant lines directly from it in my version of GCC:
// Default placement versions of operator new. inline void* operator new(std::size_t, void* __p) throw() { return __p; } inline void* operator new[](std::size_t, void* __p) throw() { return __p; } // Default placement versions of operator delete. inline void operator delete (void*, void*) throw() { } inline void operator delete[](void*, void*) throw() { }
Stick to something somewhere in the header file included in every source file that uses the new / delete location.
An example of a file that checks this:
#include <cstdio> #include <new> int main(int argc, char** argv) { typedef char const* cstr; char foobar[16]; cstr* str = new (&foobar) cstr(argc > 1 ? argv[1] : "Hello, world!"); std::puts(*str); str->~cstr(); }
In my version of GCC, this does not use libstdc++ (if -fno-exceptions ).
Now, if you want to combine this with malloc (if your platform provides this), you can do this:
#include <cstdio> #include <cstdlib> inline void* operator new (std::size_t n) {return std::malloc(n);} inline void* operator new[](std::size_t n) {return std::malloc(n);} inline void operator delete (void* p) {std::free(p);} inline void operator delete[](void* p) {std::free(p);} int main(int argc, char** argv) { typedef char const* cstr; cstr* str = new cstr(argc > 1 ? argv[1] : "Hello, world!"); std::puts(*str); delete str; }
This allows you to use the standard new / delete that you are familiar with without using libstdc++ .
Good luck