In the context of embedded software I want to make a std::vector-like container.
Vector has both size and capacity, which means vector has allocated capacity*sizeof(T)
bytes, but only size
entries are constructed.
An example
vector<string> v;
v.reserve(100)
v.resize(10)
v[9]
gives a valid string , but v[10]
gives a valid allocated memory portion of uninitialized data, so any string
method will have an undefined behaviour, like v[10]= string()
, if string& operator(const string& rhs)
tries to destroy *this
.
How can I build an object in a given memory address just using C++ compiler without including <new>
or any other C++ standard include files?
UPDATE Can I write a custom implementation of placement new operator and make final executable independant from libstdc++.so? I don't want static linking against libstdc++.a either.