Reputation: 21
I am working with one new microcontroller developed by a local company here. I am currently porting the library to work with that microcontroller. The main problem now is that the C++ library for the microcontroller does not support std::string data type. I am new in C++, hence i do need help since i need to print a string when a ip address is requested from the browser.
here is the explanation from the wiki of the microcontroller "
The SXC library and the XInC2 do not support dynamic memory allocation, and thus there is no heap. This means that data types that make use of dynamically allocated memory are currently not supported. They may be included in future versions of the SXC, but currently the poor performance that would result from the implementation such types would likely be prohibitive in many cases. As an example, the std::string data type is currently not supported.
This also means that dynamic memory related keywords are NOT included -- this includes new, delete as well as the similar C methods malloc and free.
RTTI, or Run-Time-Type-Information is also disabled. This does not prohibit polymorphism completely, however, as virtual functions and virtual inheritance are still supported. dynamic_cast between polymorphic types, for instance, is not supported due to its reliance on RTTI. static_cast and reinterpret_cast are still supported. Exceptions are currently disabled, however they are being considered for implementation. This means keywords throw, try and catch are not supported."
Is there any alternative to the string manipulation library?
thanks
Upvotes: 2
Views: 201
Reputation: 179991
In such situations, I find it useful to read "there is no heap" as "we couldn't be bothered to create a heap, so you will have to do so". The fact that malloc
and free
aren't "supported" just means that you're free to provide your own implementation and they won't collide with existing definitions.
So, what's probably the best solution is to provide your own simple malloc/free
and write your own string
class on top of that.
Now there's a warning about the poor performance. That's pretty much unavoidable. It doesn't matter much how you do your string manipulation. The reason is really economics: if you want performance from a cheap microcontroller, you get a standard design. E.g. either an 8008 or a Cortex-M. You want one made by the billions, not by the thousands.
Upvotes: 0