Possible to peek/poke to access RAM directly ?

Posted on
  • Hi,
    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 ?

    Thanks,

  • 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);
    =4
    >var b=new Uint8Array(400);E.getSizeOf(b); // 28 = 3+400/16
    =28
    >var b=new Uint8Array(1024);E.getSizeOf(b); // 67 = 3+1024/16
    =67
    >var b=new Uint8Array(10000);E.getSizeOf(b); // 628 = 3+100000/16
    =628
    
  • 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...)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Possible to peek/poke to access RAM directly ?

Posted by Avatar for Polypod @Polypod

Actions