Definition of a flat string and example #1236
Replies: 6 comments
-
Posted at 2018-10-12 by @gfwilliams I've made a note to update the Performance/Internals pages, but basically:
So in your case, your arraybuffer just isn't big enough that it makes sense to allocate it as a flat string. Make it size 32 or something and it'll work. You can however use |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-10-12 by @gfwilliams Just to add, what I suggest ( |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-11-05 by asez73 Hi, More explicitely, the pico receives some data from usart. The thing is an Ublox M8U gps device using their binary protocol: very c structs friendly and only bytes/words/long words properly aligned. You can see this to get a clear idea. Here, the interest is that payloads are almost all of a fixed length (DMA in sight), very compact (less bytes on usart fro more data) and no fancy sexagesimally odd computations on latitudes/longitudes and so on! My goal is to preallocate a few different dataviews of predefined length and then copy the incoming data from its string format to the dataview after all checksums and length controls of course. A side approach would be to use inline C for setters and getters but what in Espruino (javascript)? A dream would be to receive data from serial to an ArrayBuffer (kind of DMA) and only wake up when the serial buffer has enough bytes to analyse: so sleep walking while the interpreter is in deep sleep mode. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-11-06 by Robin Mon 2018.11.05 Hi @asez73,
While I hope I understand the gist of your request, after the 'light reading' of that struct ;-) To also avoid looping, I had to rely on @gordon for the class hierarchy for this snippet, could this be what you are after?
from class
It appears from your code examples, you may be light years away from my skills, but I was able to get FlatStrings, inline.C working with plain JavaScript. Array buffers aligned with FlatStrings accessible both by inline.C and direct array access for comparison. A simple concise summary of other docs and what is at: > 'A side approach would be to use inline C for setters and getters but what in Espruino (javascript)?' Yes, what you envision can be done that way. My method was required for fast <50msec (goal) access with large 1000byte strings, your
If I missed the concept using struct <--> DataView and concise memory allocation, others pipe in. . . . Although I feel you are of the type that would tinker with code to seek your own solutions, should you desire some basic snippets for your perusal, I'll post them here. Robin It appears you may already have the ammo you need from this example #1 of yours from nine months ago; Javascript usage of data stored-accessed in a Flat String |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-11-06 by @gfwilliams I think there are a few things that could help you out - some of which Robin already mentioned:
But yeah, doing something like:
works fine |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-11-14 by asez73 Thanks for your help, it did worked and I globally saved some time AND events stack depth. Now, I am more on 2 colateral problems: So I think we are far enough of flat strings and should open 2 other threads to handle those points. Thanks again! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-10-12 by Robin
Thr 2018.10.11
What is a 'flat string' and how is it different? Definition, documentation please?
Is it just a contiguous block, null terminated? Is there a size limit?
Skimmed over
It appears that 'flat string' may be specific, as a quick search only uncovered one reference, other than Espruino.com
Having issues with
var addrsrc = E.getAddressOf(src,true);
if(!addrsrc) throw new Error("Not a Flat String");
irratically returning 'Not a flat string', loading same data each run.
Working with
var buffer = new ArrayBuffer(8);
var n = new Uint8ClampedArray(buffer, 0, 4);
and E.compiledC
Is a flat string somehow related to Uint8ClampedArray
Not mentioned however in
Is
flatAddress
just a T/F flag and not the address of the variable? This implies that param should always be true, e.g. why would you supply 'false' if you are attempting to get the address of (E.getAddressOf) the variable supplied? Seems redundant.I have a hunch that the size of the referenced address passed or returned is causing pointer (my code) offset errors.
Beta Was this translation helpful? Give feedback.
All reactions