Демо
Код: Выделить всё
#include
enum class MsgType
{
write,
read,
reg_channel,
unreg_channel,
};
struct Message
{
MsgType type;
union
{
struct
{
void* addr;
size_t count;
} write;
struct
{
void* addr;
size_t count;
} read;
struct
{
int fd;
void* addr;
size_t count;
} reg_channel;
struct
{
int fd;
} unreg_channel;
};
};
struct SomeInterface
{
auto submit(Message& cmd)
{
switch(cmd.type)
{
case MsgType::write:
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/78696965/how-to-performantly-submit-messages-of-arbitrary-size-and-fields-to-a-common-i[/url]