libhal-google / libhal

A collection of interfaces and abstractions for embedded peripherals and devices using modern C++
Apache License 2.0
86 stars 17 forks source link

:sparkles: Add static memory hal::initialize<T>() #705

Closed kammce closed 9 months ago

kammce commented 1 year ago

hal::initialize<T>() will statically allocate and construct in-place the object of choice and return an entity<T, storage_key_t> object with a unique type signature which is used to differentiate each statically allocated object from each other. These entity objects can then be used like pointers to type T with full access to their underlying APIs, can be passed to other drivers to compose drivers, or be used with make_interface() functions to generate unique statically allocated adaptors for drivers.

kammce commented 9 months ago

This was actually a bad idea. Destructors are okay. And its okay to have unknown behavior on destruction. It will limit certain potential applications of drivers. There may be some guarantees we can make about driver destructors that should apply across all devices.