Skip to content

RFC samples converting VLA to alloca

Tyler Retzlaff dpdk-dev 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest4 patches 20 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4latencystats: use alloca instead of vla triviallib/latencystats/rte_latencystats.c+1 -13 replies
2/4hash: use alloca instead of vla triviallib/hash/rte_thash.c+1 -11 reply
3/4vhost: use alloca instead of vla sizeoflib/vhost/socket.c+3 -21 reply
4/4dispatcher: use alloca instead of vla multi dimensionallib/dispatcher/rte_dispatcher.c+3 -31 reply

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/4] RFC samples converting VLA to alloca

This series is not intended for merge. It insteat provides examples of converting use of VLAs to alloca() would look like.

what's the advantages of VLA over alloca()?

* sizeof(array) works as expected.

* multi-dimensional arrays are still arrays instead of pointers to dynamically allocated space. this means multiple subscript syntax works (unlike on a pointer) and calculation of addresses into allocated space in ascending order is performed by the compiler instead of manually.

what's the disadvantage of VLA over alloca()?

* VLA generation is subtl/implicit, there do appear to be places where a VLA is being used where it perhaps was not intended but it is hard to spot. e.g. hotpath rte_mbuf *array[burst_size]; where burst_size is not a constant expression, e.g. unintended in other syntax positions that are not intuitive, see patchwork link.

https://patchwork.dpdk.org/project/dpdk/patch/[email protected]/

for the above reasons i'd recommend only converting to alloca() where necessary (msvc has to compile it) and for the other instances leave them as they are.

Tyler Retzlaff (4):
latencystats: use alloca instead of vla trivial
hash: use alloca instead of vla trivial
vhost: use alloca instead of vla sizeof
dispatcher: use alloca instead of vla multi dimensional

 lib/dispatcher/rte_dispatcher.c     | 6 +++---
 lib/hash/rte_thash.c                | 2 +-
 lib/latencystats/rte_latencystats.c | 2 +-
 lib/vhost/socket.c                  | 5 +++--
 4 files changed, 8 insertions(+), 7 deletions(-)
Signature · 1 line
1.8.3.1