This blog is about programming and other technological things. Written by someone developing software for fun and professionally for longer than I want to admit and in more programming languages that I can remember
Recently I found an interesting OpenCV behaviour.
OpenCV cv::Mat
is built to be easy to use. It will allocate, free and reallocate it's own internal data. That's fine for most of the uses, but what if you are sensitive to extra memory allocations?
As you might expect, C++ developers very often track the memory ownership of any allocated piece of memory, especially when copying memory is not an option.
To use cv::Mat
without copying the buffer, you can use this class constructor that does not own the memory:
One common way to deal with serialised data in C++ is to map to a struct, but in Rust with memory ownership and some smart memory optimizations, it is a little more complicated.
For example, let's say a producer in C++ serialises this message:
struct book_msg {
uint8_t major_version, // byte 0: message major version
uint8_t minor_version, // byte 1: message minor version
uint8_t msg_type, // byte 2: message type
uint8_t title[20] // byte 3-23: title of the book
}
// ....
auto msg = create_msg();
comm.send(&msg, sizeof(book_msg));
How can we deserialise that in Rust?
In a C++ project I am currently working, we are using CMake/Conan for dependency resolution and planning to use flatbuffer to serialise some messages. When searching for documentation, I noticed that flatbuffers documentation is not the best one and that the integration with CMake is even harder to find, therefore, I decided to write a recipe on how to integrate it to reduce the misery of other developers around.
First, let me explain quickly how it works.
I was talking to a friend about cellular automata using Conway's Game of life as an example. Curious again after so many years that I've read it, I read again carefully the wikipedia page and I found it fascinating.
What is the better way to learn more? Implementing! However I do not want to implement it in a boring way. I want to have interesting features. Let's first talk a little bit about this 0-player fascinating game.
This blog is about programming and other technological things. Written by someone developing software for fun and professionally for longer than I want to admit and in more programming languages that I can remember