# lv_array.h (/api/misc/lv_array_h)



Array. The elements are dynamically allocated by the 'lv\_mem' module.

<ApiSummary functions="20" structs="1" macros="2" />

Functions [#functions]

<ApiMember kind="function" name="lv_array_init" file="misc/lv_array.h" line="54" url="https://github.com/lvgl/lvgl/tree/a7b95c5b0839ce901c09c205610bc2c77cc3345d/src/misc/lv_array.h#L54">
  lv_array_init [#lv_array_init]

  Init an array.

  ```c title=" " lineNumbers=1
  void lv_array_init(lv_array_t *array, uint32_t capacity, uint32_t element_size)
  ```

  <span className="sr-only">
    Parameters
  </span>

  | Name           | Type                                                 | Description                                       |
  | -------------- | ---------------------------------------------------- | ------------------------------------------------- |
  | `array`        | <ApiLink name="lv_array_t" display="lv_array_t *" /> | pointer to an `lv_array_t` variable to initialize |
  | `capacity`     | <ApiLink name="uint32_t" />                          | the initial capacity of the array                 |
  | `element_size` | <ApiLink name="uint32_t" />                          | the size of an element in bytes                   |
</ApiMember>

<ApiMember kind="function" name="lv_array_init_from_buf" file="misc/lv_array.h" line="65" url="https://github.com/lvgl/lvgl/tree/a7b95c5b0839ce901c09c205610bc2c77cc3345d/src/misc/lv_array.h#L65">
  lv_array_init_from_buf [#lv_array_init_from_buf]

  Init an array from a buffer.

  ```c title=" " lineNumbers=1
  void lv_array_init_from_buf(lv_array_t *array, void *buf, uint32_t capacity, uint32_t element_size)
  ```

  <span className="sr-only">
    Parameters
  </span>

  | Name           | Type                                                 | Description                                       |
  | -------------- | ---------------------------------------------------- | ------------------------------------------------- |
  | `array`        | <ApiLink name="lv_array_t" display="lv_array_t *" /> | pointer to an `lv_array_t` variable to initialize |
  | `buf`          | `void *`                                             | pointer to a buffer to use as the array's data    |
  | `capacity`     | <ApiLink name="uint32_t" />                          | the initial capacity of the array                 |
  | `element_size` | <ApiLink name="uint32_t" />                          | the size of an element in bytes                   |

  <Callout type="info">
    The buffer must be large enough to store `capacity` elements. The array will not release the buffer and reallocate it. The user must ensure that the buffer is valid during the lifetime of the array. And release the buffer when the array is no longer needed.
  </Callout>
</ApiMember>

<ApiMember kind="function" name="lv_array_resize" file="misc/lv_array.h" line="73" url="https://github.com/lvgl/lvgl/tree/a7b95c5b0839ce901c09c205610bc2c77cc3345d/src/misc/lv_array.h#L73">
  lv_array_resize [#lv_array_resize]

  Resize the array to the given capacity.

  ```c title=" " lineNumbers=1
  bool lv_array_resize(lv_array_t *array, uint32_t new_capacity)
  ```

  <span className="sr-only">
    Parameters
  </span>

  | Name           | Type                                                 | Description                         |
  | -------------- | ---------------------------------------------------- | ----------------------------------- |
  | `array`        | <ApiLink name="lv_array_t" display="lv_array_t *" /> | pointer to an `lv_array_t` variable |
  | `new_capacity` | <ApiLink name="uint32_t" />                          | the new capacity of the array       |

  <Callout type="info">
    if the new capacity is smaller than the current size, the array will be truncated.
  </Callout>
</ApiMember>

<ApiMember kind="function" name="lv_array_deinit" file="misc/lv_array.h" line="79" url="https://github.com/lvgl/lvgl/tree/a7b95c5b0839ce901c09c205610bc2c77cc3345d/src/misc/lv_array.h#L79">
  lv_array_deinit [#lv_array_deinit]

  Deinit the array, and free the allocated memory

  ```c title=" " lineNumbers=1
  void lv_array_deinit(lv_array_t *array)
  ```

  <span className="sr-only">
    Parameters
  </span>

  | Name    | Type                                                 | Description                                         |
  | ------- | ---------------------------------------------------- | --------------------------------------------------- |
  | `array` | <ApiLink name="lv_array_t" display="lv_array_t *" /> | pointer to an `lv_array_t` variable to deinitialize |
</ApiMember>

<ApiMember kind="function" name="lv_array_size" file="misc/lv_array.h" line="86" url="https://github.com/lvgl/lvgl/tree/a7b95c5b0839ce901c09c205610bc2c77cc3345d/src/misc/lv_array.h#L86">
  lv_array_size [#lv_array_size]

  Return how many elements are stored in the array.

  ```c title=" " lineNumbers=1
  static uint32_t lv_array_size(const lv_array_t *array)
  ```

  <span className="sr-only">
    Parameters
  </span>

  | Name    | Type                                                       | Description                         |
  | ------- | ---------------------------------------------------------- | ----------------------------------- |
  | `array` | <ApiLink name="lv_array_t" display="const lv_array_t *" /> | pointer to an `lv_array_t` variable |

  **Returns:** <ApiLink name="uint32_t" /> — the number of elements stored in the array
</ApiMember>

<ApiMember kind="function" name="lv_array_capacity" file="misc/lv_array.h" line="96" url="https://github.com/lvgl/lvgl/tree/a7b95c5b0839ce901c09c205610bc2c77cc3345d/src/misc/lv_array.h#L96">
  lv_array_capacity [#lv_array_capacity]

  Return the capacity of the array, i.e. how many elements can be stored.

  ```c title=" " lineNumbers=1
  static uint32_t lv_array_capacity(const lv_array_t *array)
  ```

  <span className="sr-only">
    Parameters
  </span>

  | Name    | Type                                                       | Description                         |
  | ------- | ---------------------------------------------------------- | ----------------------------------- |
  | `array` | <ApiLink name="lv_array_t" display="const lv_array_t *" /> | pointer to an `lv_array_t` variable |

  **Returns:** <ApiLink name="uint32_t" /> — the capacity of the array
</ApiMember>

<ApiMember kind="function" name="lv_array_is_empty" file="misc/lv_array.h" line="106" url="https://github.com/lvgl/lvgl/tree/a7b95c5b0839ce901c09c205610bc2c77cc3345d/src/misc/lv_array.h#L106">
  lv_array_is_empty [#lv_array_is_empty]

  Return if the array is empty

  ```c title=" " lineNumbers=1
  static bool lv_array_is_empty(const lv_array_t *array)
  ```

  <span className="sr-only">
    Parameters
  </span>

  | Name    | Type                                                       | Description                         |
  | ------- | ---------------------------------------------------------- | ----------------------------------- |
  | `array` | <ApiLink name="lv_array_t" display="const lv_array_t *" /> | pointer to an `lv_array_t` variable |

  **Returns:** <ApiLink name="bool" /> — true: array is empty; false: array is not empty
</ApiMember>

<ApiMember kind="function" name="lv_array_is_full" file="misc/lv_array.h" line="116" url="https://github.com/lvgl/lvgl/tree/a7b95c5b0839ce901c09c205610bc2c77cc3345d/src/misc/lv_array.h#L116">
  lv_array_is_full [#lv_array_is_full]

  Return if the array is full

  ```c title=" " lineNumbers=1
  static bool lv_array_is_full(const lv_array_t *array)
  ```

  <span className="sr-only">
    Parameters
  </span>

  | Name    | Type                                                       | Description                         |
  | ------- | ---------------------------------------------------------- | ----------------------------------- |
  | `array` | <ApiLink name="lv_array_t" display="const lv_array_t *" /> | pointer to an `lv_array_t` variable |

  **Returns:** <ApiLink name="bool" /> — true: array is full; false: array is not full
</ApiMember>

<ApiMember kind="function" name="lv_array_copy" file="misc/lv_array.h" line="127" url="https://github.com/lvgl/lvgl/tree/a7b95c5b0839ce901c09c205610bc2c77cc3345d/src/misc/lv_array.h#L127">
  lv_array_copy [#lv_array_copy]

  Copy an array to another.

  ```c title=" " lineNumbers=1
  void lv_array_copy(lv_array_t *target, const lv_array_t *source)
  ```

  <span className="sr-only">
    Parameters
  </span>

  | Name     | Type                                                       | Description                                      |
  | -------- | ---------------------------------------------------------- | ------------------------------------------------ |
  | `target` | <ApiLink name="lv_array_t" display="lv_array_t *" />       | pointer to an `lv_array_t` variable to copy to   |
  | `source` | <ApiLink name="lv_array_t" display="const lv_array_t *" /> | pointer to an `lv_array_t` variable to copy from |

  <Callout type="info">
    this will create a new array with the same capacity and size as the source array.
  </Callout>
</ApiMember>

<ApiMember kind="function" name="lv_array_clear" file="misc/lv_array.h" line="133" url="https://github.com/lvgl/lvgl/tree/a7b95c5b0839ce901c09c205610bc2c77cc3345d/src/misc/lv_array.h#L133">
  lv_array_clear [#lv_array_clear]

  Remove all elements in array.

  ```c title=" " lineNumbers=1
  static void lv_array_clear(lv_array_t *array)
  ```

  <span className="sr-only">
    Parameters
  </span>

  | Name    | Type                                                 | Description                         |
  | ------- | ---------------------------------------------------- | ----------------------------------- |
  | `array` | <ApiLink name="lv_array_t" display="lv_array_t *" /> | pointer to an `lv_array_t` variable |
</ApiMember>

<ApiMember kind="function" name="lv_array_shrink" file="misc/lv_array.h" line="142" url="https://github.com/lvgl/lvgl/tree/a7b95c5b0839ce901c09c205610bc2c77cc3345d/src/misc/lv_array.h#L142">
  lv_array_shrink [#lv_array_shrink]

  Shrink the memory capacity of array if necessary.

  ```c title=" " lineNumbers=1
  void lv_array_shrink(lv_array_t *array)
  ```

  <span className="sr-only">
    Parameters
  </span>

  | Name    | Type                                                 | Description                         |
  | ------- | ---------------------------------------------------- | ----------------------------------- |
  | `array` | <ApiLink name="lv_array_t" display="lv_array_t *" /> | pointer to an `lv_array_t` variable |
</ApiMember>

<ApiMember kind="function" name="lv_array_remove" file="misc/lv_array.h" line="153" url="https://github.com/lvgl/lvgl/tree/a7b95c5b0839ce901c09c205610bc2c77cc3345d/src/misc/lv_array.h#L153">
  lv_array_remove [#lv_array_remove]

  Remove the element at the specified position in the array.

  This function keeps the array order. Complexity is O(n)

  ```c title=" " lineNumbers=1
  lv_result_t lv_array_remove(lv_array_t *array, uint32_t index)
  ```

  <span className="sr-only">
    Parameters
  </span>

  | Name    | Type                                                 | Description                         |
  | ------- | ---------------------------------------------------- | ----------------------------------- |
  | `array` | <ApiLink name="lv_array_t" display="lv_array_t *" /> | pointer to an `lv_array_t` variable |
  | `index` | <ApiLink name="uint32_t" />                          | the index of the element to remove  |

  **Returns:** <ApiLink name="lv_result_t" /> — LV\_RESULT\_OK: success, otherwise: error
</ApiMember>

<ApiMember kind="function" name="lv_array_remove_unordered" file="misc/lv_array.h" line="164" url="https://github.com/lvgl/lvgl/tree/a7b95c5b0839ce901c09c205610bc2c77cc3345d/src/misc/lv_array.h#L164">
  lv_array_remove_unordered [#lv_array_remove_unordered]

  Remove the element at the specified position in the array.

  This function does not guarantee the array order. Complexity is O(1)

  ```c title=" " lineNumbers=1
  lv_result_t lv_array_remove_unordered(lv_array_t *array, uint32_t index)
  ```

  <span className="sr-only">
    Parameters
  </span>

  | Name    | Type                                                 | Description                         |
  | ------- | ---------------------------------------------------- | ----------------------------------- |
  | `array` | <ApiLink name="lv_array_t" display="lv_array_t *" /> | pointer to an `lv_array_t` variable |
  | `index` | <ApiLink name="uint32_t" />                          | the index of the element to remove  |

  **Returns:** <ApiLink name="lv_result_t" /> — LV\_RESULT\_OK: success, otherwise: error
</ApiMember>

<ApiMember kind="function" name="lv_array_erase" file="misc/lv_array.h" line="175" url="https://github.com/lvgl/lvgl/tree/a7b95c5b0839ce901c09c205610bc2c77cc3345d/src/misc/lv_array.h#L175">
  lv_array_erase [#lv_array_erase]

  Remove from the array either a single element or a range of elements (\[start, end)).

  ```c title=" " lineNumbers=1
  lv_result_t lv_array_erase(lv_array_t *array, uint32_t start, uint32_t end)
  ```

  <span className="sr-only">
    Parameters
  </span>

  | Name    | Type                                                 | Description                                              |
  | ------- | ---------------------------------------------------- | -------------------------------------------------------- |
  | `array` | <ApiLink name="lv_array_t" display="lv_array_t *" /> | pointer to an `lv_array_t` variable                      |
  | `start` | <ApiLink name="uint32_t" />                          | the index of the first element to be removed             |
  | `end`   | <ApiLink name="uint32_t" />                          | the index of the first element that is not to be removed |

  **Returns:** <ApiLink name="lv_result_t" /> — LV\_RESULT\_OK: success, otherwise: error

  <Callout type="info">
    This effectively reduces the container size by the number of elements removed.
  </Callout>

  <Callout type="info">
    When start equals to end, the function has no effect.
  </Callout>
</ApiMember>

<ApiMember kind="function" name="lv_array_concat" file="misc/lv_array.h" line="184" url="https://github.com/lvgl/lvgl/tree/a7b95c5b0839ce901c09c205610bc2c77cc3345d/src/misc/lv_array.h#L184">
  lv_array_concat [#lv_array_concat]

  Concatenate two arrays. Adds new elements to the end of the array.

  ```c title=" " lineNumbers=1
  lv_result_t lv_array_concat(lv_array_t *array, const lv_array_t *other)
  ```

  <span className="sr-only">
    Parameters
  </span>

  | Name    | Type                                                       | Description                         |
  | ------- | ---------------------------------------------------------- | ----------------------------------- |
  | `array` | <ApiLink name="lv_array_t" display="lv_array_t *" />       | pointer to an `lv_array_t` variable |
  | `other` | <ApiLink name="lv_array_t" display="const lv_array_t *" /> | pointer to the array to concatenate |

  **Returns:** <ApiLink name="lv_result_t" /> — LV\_RESULT\_OK: success, otherwise: error

  <Callout type="info">
    The destination array is automatically expanded as necessary.
  </Callout>
</ApiMember>

<ApiMember kind="function" name="lv_array_push_back" file="misc/lv_array.h" line="194" url="https://github.com/lvgl/lvgl/tree/a7b95c5b0839ce901c09c205610bc2c77cc3345d/src/misc/lv_array.h#L194">
  lv_array_push_back [#lv_array_push_back]

  Push back element. Adds a new element to the end of the array. If the array capacity is not enough for the new element, the array will be resized automatically.

  ```c title=" " lineNumbers=1
  lv_result_t lv_array_push_back(lv_array_t *array, const void *element)
  ```

  <span className="sr-only">
    Parameters
  </span>

  | Name      | Type                                                 | Description                                                   |
  | --------- | ---------------------------------------------------- | ------------------------------------------------------------- |
  | `array`   | <ApiLink name="lv_array_t" display="lv_array_t *" /> | pointer to an `lv_array_t` variable                           |
  | `element` | `const void *`                                       | pointer to the element to add. NULL to push an empty element. |

  **Returns:** <ApiLink name="lv_result_t" /> — LV\_RESULT\_OK: success, otherwise: error

  <Callout type="info">
    If the element is NULL, it will be added as an empty element.
  </Callout>
</ApiMember>

<ApiMember kind="function" name="lv_array_assign" file="misc/lv_array.h" line="203" url="https://github.com/lvgl/lvgl/tree/a7b95c5b0839ce901c09c205610bc2c77cc3345d/src/misc/lv_array.h#L203">
  lv_array_assign [#lv_array_assign]

  Assigns one content to the array, replacing its current content.

  ```c title=" " lineNumbers=1
  lv_result_t lv_array_assign(lv_array_t *array, uint32_t index, const void *value)
  ```

  <span className="sr-only">
    Parameters
  </span>

  | Name    | Type                                                 | Description                         |
  | ------- | ---------------------------------------------------- | ----------------------------------- |
  | `array` | <ApiLink name="lv_array_t" display="lv_array_t *" /> | pointer to an `lv_array_t` variable |
  | `index` | <ApiLink name="uint32_t" />                          | the index of the element to replace |
  | `value` | `const void *`                                       | pointer to the elements to add      |

  **Returns:** <ApiLink name="lv_result_t" /> — true: success; false: error
</ApiMember>

<ApiMember kind="function" name="lv_array_at" file="misc/lv_array.h" line="211" url="https://github.com/lvgl/lvgl/tree/a7b95c5b0839ce901c09c205610bc2c77cc3345d/src/misc/lv_array.h#L211">
  lv_array_at [#lv_array_at]

  Returns a pointer to the element at position n in the array.

  ```c title=" " lineNumbers=1
  void * lv_array_at(const lv_array_t *array, uint32_t index)
  ```

  <span className="sr-only">
    Parameters
  </span>

  | Name    | Type                                                       | Description                         |
  | ------- | ---------------------------------------------------------- | ----------------------------------- |
  | `array` | <ApiLink name="lv_array_t" display="const lv_array_t *" /> | pointer to an `lv_array_t` variable |
  | `index` | <ApiLink name="uint32_t" />                                | the index of the element to return  |

  **Returns:** `void *` — a pointer to the requested element, NULL if `index` is out of range
</ApiMember>

<ApiMember kind="function" name="lv_array_front" file="misc/lv_array.h" line="218" url="https://github.com/lvgl/lvgl/tree/a7b95c5b0839ce901c09c205610bc2c77cc3345d/src/misc/lv_array.h#L218">
  lv_array_front [#lv_array_front]

  Returns a pointer to the first element in the array.

  ```c title=" " lineNumbers=1
  static void * lv_array_front(const lv_array_t *array)
  ```

  <span className="sr-only">
    Parameters
  </span>

  | Name    | Type                                                       | Description                         |
  | ------- | ---------------------------------------------------------- | ----------------------------------- |
  | `array` | <ApiLink name="lv_array_t" display="const lv_array_t *" /> | pointer to an `lv_array_t` variable |

  **Returns:** `void *` — a pointer to the first element in the array
</ApiMember>

<ApiMember kind="function" name="lv_array_back" file="misc/lv_array.h" line="227" url="https://github.com/lvgl/lvgl/tree/a7b95c5b0839ce901c09c205610bc2c77cc3345d/src/misc/lv_array.h#L227">
  lv_array_back [#lv_array_back]

  Returns a pointer to the last element in the array.

  ```c title=" " lineNumbers=1
  static void * lv_array_back(const lv_array_t *array)
  ```

  <span className="sr-only">
    Parameters
  </span>

  | Name    | Type                                                       | Description                         |
  | ------- | ---------------------------------------------------------- | ----------------------------------- |
  | `array` | <ApiLink name="lv_array_t" display="const lv_array_t *" /> | pointer to an `lv_array_t` variable |
</ApiMember>

Structs [#structs]

<ApiMember kind="struct" name="_lv_array_t">
  \_lv_array_t [#_lv_array_t]

  Description of a array

  | Member         | Type                                           | Description |
  | -------------- | ---------------------------------------------- | ----------- |
  | `data`         | <ApiLink name="uint8_t" display="uint8_t *" /> |             |
  | `size`         | <ApiLink name="uint32_t" />                    |             |
  | `capacity`     | <ApiLink name="uint32_t" />                    |             |
  | `element_size` | <ApiLink name="uint32_t" />                    |             |
  | `inner_alloc`  | <ApiLink name="bool" />                        |             |
</ApiMember>

Macros [#macros]

<ApiMember kind="macro" name="LV_ARRAY_DEFAULT_CAPACITY" file="misc/lv_array.h" line="23" url="https://github.com/lvgl/lvgl/tree/a7b95c5b0839ce901c09c205610bc2c77cc3345d/src/misc/lv_array.h#L23">
  LV_ARRAY_DEFAULT_CAPACITY [#lv_array_default_capacity]

  ```c title=" " lineNumbers=1
  #define LV_ARRAY_DEFAULT_CAPACITY 4
  ```
</ApiMember>

<ApiMember kind="macro" name="LV_ARRAY_DEFAULT_SHRINK_RATIO" file="misc/lv_array.h" line="27" url="https://github.com/lvgl/lvgl/tree/a7b95c5b0839ce901c09c205610bc2c77cc3345d/src/misc/lv_array.h#L27">
  LV_ARRAY_DEFAULT_SHRINK_RATIO [#lv_array_default_shrink_ratio]

  ```c title=" " lineNumbers=1
  #define LV_ARRAY_DEFAULT_SHRINK_RATIO 2
  ```
</ApiMember>

Dependencies [#dependencies]

<FileIncludes includes="[&#x22;lv_types.h&#x22;]" includedBy="[&#x22;lv_draw_vector.h&#x22;, &#x22;lv_g2d_buf_map.h&#x22;, &#x22;lv_draw_vg_lite_type.h&#x22;, &#x22;lv_gltf_data_internal.hpp&#x22;, &#x22;lv_svg.h&#x22;, &#x22;lv_svg_token.h&#x22;, &#x22;lv_event.h&#x22;, &#x22;lv_translation.h&#x22;, &#x22;lv_translation_private.h&#x22;]" transitiveIncludes="[&#x22;lv_conf_internal.h&#x22;, &#x22;lv_conf_kconfig.h&#x22;]" />
