Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function to convert a memory area to a String/ArrayBuffer #738

Closed
gfwilliams opened this issue Nov 27, 2015 · 6 comments
Closed

Function to convert a memory area to a String/ArrayBuffer #738

gfwilliams opened this issue Nov 27, 2015 · 6 comments

Comments

@gfwilliams
Copy link
Member

E.memoryArea(addr, len) -> ArrayBuffer

Where that ArrayBuffer directly accessed the underlying memory area. In fact JSV_GET_AS_CHAR_ARRAY should be able to use the pointer directly.

It's not of much use for RAM, but would be amazingly useful for Flash memory (sadly it wouldn't be ESP8266-friendly, but potentially it could be worked around).

Specifically this would be very useful for storing certificates/keys for HTTPS: http://forum.espruino.com/conversations/277780/?offset=25#12650582

@gfwilliams
Copy link
Member Author

For this to be properly useful we'd want jsvStringIterator to be able to handle it as well - this would allow some pretty cool things:

  • code to be evaluated directly from flash
  • waveforms to the played directly from flash

There must be a few other cases this would be useful in too.

@tve
Copy link
Contributor

tve commented Nov 27, 2015

+100 on code directly evaluated from flash!

Can you explain why it wouldn't be esp8266 friendly?

When you say "jsvStringIterator to be able to handle it as well", what does that mean? (I don't know much about that function.) Would that allow code to be executed from flash without loading it all into RAM? That would be awesome.

@SpenceKonde
Copy link

It would be awesome if we could stuff a function into flash! This would do it, wouldn't it? - ie, function bigLongStaticFunction(a,b,c){return eval(E.memoryArea(0xF00D,4000));} // run 4000 byte long block of code from flash starting at address 0xF00D)?

@gfwilliams
Copy link
Member Author

Yes, something like that would work just fine. It could be useful!

@gfwilliams
Copy link
Member Author

jsvStringIterator just provides getChar/setChar/nextChar kind of functions - and hides the jumping around between jsvars that happens under the hood. Internally it has currentVar, currentChar, varLength fields, and they could be fiddled such that it would actually execute from flash.

Can you explain why it wouldn't be esp8266 friendly?

jslex.c uses what's basically an inlined jsvStringIterator (modified slightly iirc to make it faster). Thing is it reads characters one at a time, which I didn't think would work with flash memory on ESP8266?

Potentially you could change both jsvStringIterator and jslex to read a word at a time, but it might hurt performance

@gfwilliams
Copy link
Member Author

JSV_GET_AS_CHAR_ARRAY needs to know about this as well, and a general grep for jsvGetFlatStringPointer might be an idea to see if there are other places we can use them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants