iotjs icon indicating copy to clipboard operation
iotjs copied to clipboard

Introduce String wrapper for IoTjs

Open ILyoan opened this issue 11 years ago • 3 comments

From the start of the project we had used char* to represent ASCII string data. And from eef9e4ff7d45e3ffe851bf67f3157addbcd7410a it has changed to jschar* to represent UTF8 encoded string data.

But this change prevent using ASCII char* string data even if ascii data is itself UTF8 encoded. developers should use JSCT macro to convert char* to jschar* everywhere that could be burden.

My plan is to introduce String class that is wrapping string data encoded with either ASCII or UTF8. And revert JObject member to provide ASCII string parameters instead of jschar* since I think there will be no problem exposing APIs that take ASCII string for ASCII can be converted to UTF8 without problems. But the member function should also take UTF8 string, here String plays role. By providing overloaded function that take String object that JObject binding functions will provide not only ASCII but also UTF8 string for its parameter.

ILyoan avatar Jul 08 '15 09:07 ILyoan

Can there be more memory usage? It would be nice if not use too much buffer allocations.

seanshpark avatar Jul 08 '15 09:07 seanshpark

The total usage of memory for hold string data will be the same as before. Current implementation is like:

jschar* buff = AllocateBuffer();
copy javascript string to buffer.
LocalString refers the buffer.
Use the LocalString object.
Buffer will be freed when LocalString out of scope.

Will change to:

String object allocates buffer.
copy javascript string to String.
Use the String object.
Buffer will be freed when String out of scope.

And JObject binding will also become take String object for UTF8 and ANSI C(ASCII) string as well as char* for ASCII string.

I think char should be enough to represent byte without confusion that octet and jschar could be removed from our source tree.

ILyoan avatar Jul 08 '15 11:07 ILyoan

Closing as #123 landed

ILyoan avatar Jul 14 '15 06:07 ILyoan