Closed lexxvir closed 6 years ago
No, queues cannot be used for heap allocated data structures, which is by FreeRTOS's design, and which is enforced using Rust's copy semantics. Try to redesign your application to pass only Copy structures. If you really need that, you might want to look into storing data into a global, shared vector (Arc<Mutex<Vec>>) and passing plain IDs using queues.
Sorry for annoying, I believe that in FreeRTOS it possible to allocation data in heap and then send pointer to allocated memory to queue. Then receiver will be responsible to free memory. Of course allocated memory must not used by sender when he sent pointer to queue.
In Rust we can use Box
for this purpose, but, as I understood now, it is require separated implementation, that will be:
Box
by into_raw
Box
at receiver side by Box::from_raw
from raw pointerSure, you can do that. No changes are necessary within this Rust library, you can easily implement that as a trivial typed Rust struct that only holds a single usize pointer. But support for this won't be added to this project.
Is it possible to pass huge struct through queue without copying whole struct?
It seems that
freertos.rs
makes copying ofitem
inQueue::send()
(though it possibly be removed by optimizations), then FreeRTOS'xQueueSend
also does copy.Box<T>
could be used for this purpose but as I see,Box
doesn't implementCopy
trait that required byQueue
.