On Tue, 1 Dec 2026 20:29:46 +0100 Morten Brørup <[email protected]> wrote:
> > From: Bruce Richardson [mailto:[email protected]] > > Sent: Tuesday, 1 December 2026 19.23 > > > > Many drivers allocate small control-path messages, which consist of a > > header structure followed by a variable-length array, using malloc and > > free, which adds error handling and the risk of leaks on error paths. > > > > Add RTE_DEFINE_FLEX and RTE_DEFINE_FLEX_BYTES macros to define such > > buffers on the stack instead, (similar to equivalent macros in Linux > > kernel). The buffer is a union of a byte array and the structure type, > > giving correct alignment and type-safe access via a pointer, with the > > byte array first so that zero-initialization covers the whole buffer. > > > > Signed-off-by: Bruce Richardson <[email protected]> > > --- > > I thought we wanted to get rid of variable length arrays... > Could this be implemented using alloca() instead? > > There is difference between Variable Length Array (VLA) which is on stack buffer like: void foo(size_t n) { int results[n]; ... And Flexible Array which is structure with variable amount of data at the end: struct foo { int nflow; struct flow flows[]; } The Linux kernel also uses Gcc/clang counted by, can these macros do that?

