While trying to design a good API for string/list without memory allocation, I looked at caller provided buffers and lazy value lowering and was unable to design something which felt easy to use.
E.g. heapless::String
always required an upper bound which ideally would be defined in the WIT, thus I ended up with bounded lists and strings which by using return value optimization already avoid all allocations without requiring CPB or LVL.
So my question to SIG embedded: Do these bounded containers already solve many problems with the component model for microcontrollers or am I too optimistic about it?
Christof Petig said:
So my question to SIG embedded: Do these bounded containers already solve many problems with the component model for microcontrollers or am I too optimistic about it?
you're too optimistic, but then, so am I. :-)
It might help on some use cases. It depends on the setup. In a realtime capable system, one should not malloc/free at all (or at least minimize it). So, yes, there it might help.
On the other hand: We did some internal measurements with an artificial example, showing that malloc in wamr can perform faster (up to factor 2) than a native malloc (which is not surprising with the simple linear memory and not using the "system's" malloc in wasm). So, regarding "speed" this seems to be a lesser problem. More problematic is mem fragmentation, hence using only (statically) pre-allocated memory might help, if you can set it up properly.
(I recall, that there are languages which do not "have" a malloc in their programming model, hence Strings have a maximum size (like e.g. 16k). This, of course, leads to the problem, that a user (=the wasm app writer), who wants to read/parse a json/yml/xml file, might not be able to use some OSS parsers... or the user itself must adapt the OSS parser)
What do you think @Chris Woods @Stephen Berard @Dominik Tacke @Wang Xin ?
[edited typos]
Last updated: Dec 23 2024 at 13:07 UTC