string to hex string /hex string to string conversion #7597
Replies: 1 comment
-
Posted at 2018-11-26 by @gfwilliams How much data are you looking at sending? If you don't mind a bit of (short-term) memory overhead you can do:
This should be reasonably fast, but it'll allocate an array so for anything over a few hundred bytes it could cause problems. String append is actually pretty fast & efficient in Espruino, so using your idea with a few of the hacks from above you might find this is better:
It might be that you can configure the module to output data in binary though? That might be an easier way of working. Posted at 2018-11-26 by Kartman That code is like decoding a puzzle! I saw the 256 + bit and I'm thinking What!! Then I twigged that it is to ensure there's at least two hex chars. Thanks for the tips. Unfortunately the Quectel BC95 uses hex ascii. Why? Who knows. I can't think of any other AT module that does it that way. We were having some memory problems especially when receiving, so I had thought my code was not too efficient. I had it in my mind that there might be a simple way to use a byte array and cast it to a string. That way there's no copy and allocate. Posted at 2018-11-27 by Nadnerb I put together this implementation using a byte array without having to copy and allocate new strings.
After running a process.memory() command before and after these changes, I can't see any significant memory savings. Should we expect any improvements in memory usage by using a byte array, or does the string append provide the best use of memory allocation? What improvements could we make to this implementation to improve memory allocation? Posted at 2018-11-27 by @gfwilliams String append with That's a great use of @KarTmaN yes, the code is a bit cryptic! Unfortunately there's nothing built-in. Node.js has |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2018-11-26 by Kartman
The Quectel BC95 module expects the data payload as hex strings. Are the following methods, the most memory efficient way of doing this?
and conversely:
From my limited understanding, this code would create a string, append and create a new string, rinse and repeat. This seems like a bit of overhead. I did consider typed arrays, but how do I convert these back to a string in one go?
Beta Was this translation helpful? Give feedback.
All reactions