Is it possible to read/write data directly in RAM at byte level with peek/poke ? I think of possibly storing more data in less memory than the limit of ~10bytes per byte with strings or typed arrays. It would be nice to be able to do a 1byte/byte data storage in ram like we do in flash.
In this thread (http://forum.espruino.com/conversations/288002/), they use peek to write at stackEndAddress in memory with ARM. But except the end of the stack with arm, is there a way in other boards, e.g. ESP8266, to allocate an area of RAM and get it's address for poking freely and safely ?
You should still be able to use peek and poke to access RAM. You wouldn't be able to allocate it, but you could at least find an area that was free and pray.
However it's worth noting that typed arrays (apart from a 16 byte header) store bytes 1:1 - so realistically you might as well just do a big new Uint8Array(...) and save yourself a lot of trouble :)
Happy to hear that. How to find such a free area ? What address should I look for ? All I know is that RAM starts at 0x20000000. Should I start to write there until something bad happens ?
The Uint8Array header seem to be 3 blocks long, even for short arrays. But apart from that, its store bytes 1:1 like you said. Thanks a lot, I will use that.
>var b=new Uint8Array(16);E.getSizeOf(b);
>var b=new Uint8Array(400);E.getSizeOf(b); // 28 = 3+400/16
>var b=new Uint8Array(1024);E.getSizeOf(b); // 67 = 3+1024/16
>var b=new Uint8Array(10000);E.getSizeOf(b); // 628 = 3+100000/16
Ahh, now there's a question. There is process.memory() that has some addresses in - but maybe an ESP8266 expert can weigh in here?
And yes - sorry - there's the Uint8Array block, an ArrayBuffer block, and then a backing 'flat string' for the data - so 3 blocks.
You can avoid the hassle of thinking of (absolute) addresses... As @Gordon mentions, allocation an Uint8Array (at the begin of your code) and using all kinds of views are a very easy and convenient way to do what you might want to do... (Nothing wrong with praying... - it's a very wise thing... just not for covering up subpar choices...)
Don't worry about formatting, just type in the text and we'll take care of making sense of it. We will auto-convert links, and if you put asterisks around words we will make them bold.
For a full reference visit the Markdown syntax.
© Espruino, powered by microcosm.
Report a problem