Module avr_progmem::wrapper
source · Expand description
Best-effort safe wrapper for progmem.
This module offers the ProgMem
struct that wraps pointers into progmem,
and only gives access to that value via methods that first load the value
into the normal data memory domain.
This is also the reason why the value must be Copy
and is always returned
by-value instead of by-reference (since the value is not in the data memory
where it could be referenced).
Since the ProgMem
struct loads the value using special instructions,
it really must be in progmem, otherwise it would be undefined behavior
to use any of its methods.
Therefore, its constructor is unsafe
where the
caller must guarantee that the given pointer truly points to a valid value
stored in progmem.
As convenience, the progmem
macro is offered that will create
a static
in progmem with the given value and wrap a pointer to it in the
ProgMem
struct for you.