# C++: Capacity of variable length array

**URL:** <https://forum.opencyphal.org/t/c-capacity-of-variable-length-array/1700>\
**Category:** Nunavut\
**Created:** [July 3, 2022, 1:51pm UTC](https://forum.opencyphal.org/t/c-capacity-of-variable-length-array/1700 "2022-07-03T13:51:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JustinOng](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/justinong/32/1182_2.png) [@JustinOng](https://forum.opencyphal.org/u/JustinOng)\
**Post date:** [July 3, 2022, 1:51pm UTC](https://forum.opencyphal.org/t/c-capacity-of-variable-length-array/1700/1 "2022-07-03T13:51:12Z")

</div>

Hello, I’ve been experimenting with the C++ language output of nunavut.

I might have missed something, but I don’t see a way for an application to retrieve the maximum capacity of a variable length array from the generated types.

For example, for `uavcan/primitive/Unstructured.1.0`,

In the generated C type, the capacity is defined:  
`#define uavcan_primitive_Unstructured_1_0_value_ARRAY_CAPACITY_ 256U`

A copy of the C++ type can be found [here](https://pastebin.com/xVquVS36).

Is there a way to get the capacity of `value` from the C++ type?

---

<div class="post-metadata">

**Author:** ![pavel.kirienko](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/pavel.kirienko/32/9_2.png) [@pavel.kirienko](https://forum.opencyphal.org/u/pavel.kirienko)\
**Post date:** [July 3, 2022, 4:03pm UTC](https://forum.opencyphal.org/t/c-capacity-of-variable-length-array/1700/2 "2022-07-03T16:03:44Z")

</div>

I think this is not possible at the moment. @ASMik can you please confirm?

---

<div class="post-metadata">

**Author:** ![ASMik](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/asmik/32/990_2.png) [@ASMik](https://forum.opencyphal.org/u/ASMik)\
**Post date:** [July 4, 2022, 11:22am UTC](https://forum.opencyphal.org/t/c-capacity-of-variable-length-array/1700/3 "2022-07-04T11:22:10Z")

</div>

Yes, currently this constant is not available. I think we should add it to generated C++. See [this PR](https://github.com/OpenCyphal/nunavut/pull/259)

---

<div class="post-metadata">

**Author:** ![scottdixon](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/scottdixon/32/39_2.png) [@scottdixon](https://forum.opencyphal.org/u/scottdixon)\
**Post date:** [July 5, 2022, 10:00pm UTC](https://forum.opencyphal.org/t/c-capacity-of-variable-length-array/1700/4 "2022-07-05T22:00:06Z")

</div>

This depends on the C++ type you generate. The built-in `VariableLengthArray` has a public property `max_size`. If you use `std::vector` then we are missing this data and need to provide it. Let me look at the PR from @ASMik …
