Provide documentation and options for memory allocation #407
-
ContextI was not able to find any documentation about what allocation modes DeviceScript supports, eg static or dynamic, or if it allows usage of a custom allocator. This is a very nuanced topic in embedded systems, where use of Further reading:
For collections (such as array) one strategy is to have a bounded (fixed size) array. In the embedded Rust space, there are crates available such as Further reading: The Embedded Rust Book - Collections. Finally, another example would be FreeRTOS's approach to memory management. It provides several heaps the developer can choose from at build time. heap_1 - the very simplest, does not permit memory to be freed. DeviceScriptAlthough I see that there is some mention of conserving memory in the docs on buffers:
There are still no guarantees about the runtime, with comments such as this: devicescript/runtime/devicescript/objects.c Line 521 in 9f83802 This leaves a few questions about safety and guarantees for embedded scenarios.
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Excellent question! I assume you're asking about using a DeviceScript runtime, not porting the runtime to a different MCU. First, a qualifier - the "professional" refers to the TypeScript developers and experience, and we will definitely not cover all professional uses of embedded systems, now done in C, C++ or Rust (let alone assembly). However, we think that there are many scenarios where using an ESP32 or RP2040 in place even of an 8-bit chip is cost-effective, due to the costs of developing software. Simple (though not necessarily 8-bit-simple!) embedded scenarios are DeviceScript sweet spot. In other words, our focus is to enable TypeScript developers to do embedded stuff that no-one did before, because it was not cost-effective, and not so much to enable embedded developers to do their current projects more efficiently. The DeviceScript code generally allocates freely, as expected by (non-embedded) TypeScript developers. The DeviceScript runtime uses a precise garbage collector (GC). The GC is currently non-compacting, though that may be fixed in future, see issue #255. When the program runs out of memory, it is terminated and restarted (after a few seconds). Similarly, the program is restarted upon an unhandled exception (though we plan to allow overriding that). Note, that in either case the device is not restarted, only the user program, and the exception may be reported via the cloud connection. We do not plan to allow any more precise control over memory allocation, though we may provide better ways of monitoring usage. I hope this helps! |
Beta Was this translation helpful? Give feedback.
Excellent question!
I assume you're asking about using a DeviceScript runtime, not porting the runtime to a different MCU.
First, a qualifier - the "professional" refers to the TypeScript developers and experience, and we will definitely not cover all professional uses of embedded systems, now done in C, C++ or Rust (let alone assembly). However, we think that there are many scenarios where using an ESP32 or RP2040 in place even of an 8-bit chip is cost-effective, due to the costs of developing software. Simple (though not necessarily 8-bit-simple!) embedded scenarios are DeviceScript sweet spot.
In other words, our focus is to enable TypeScript developers to do embedded stuff that no-one…