---
name: "wl_array"
section: "3"
platform: "linux"
package: "wayland-docs"
version: "1.26.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/wl_array"
---

# wl\_array(3)

## NAME

wl\_array

## SYNOPSIS

\#include \<wayland-util.h\>

### Public Member Functions

void **wl\_array\_init** (struct **wl\_array** \*array)\
 void **wl\_array\_release** (struct **wl\_array** \*array)\
 void \* **wl\_array\_add** (struct **wl\_array** \*array, size\_t **size**)\
 int **wl\_array\_copy** (struct **wl\_array** \*array, struct **wl\_array** \*source)\

### Data Fields

size\_t **size**\
 size\_t **alloc**\
 void \* **data**\

### Related Symbols

(Note that these are not member symbols.)  #define **wl\_array\_for\_each**(pos,  array)\

## Detailed Description

Dynamic array

A **wl\_array** is a dynamic array that can only grow until released. It is intended for relatively small allocations whose size is variable or not known in advance. While construction of a **wl\_array** does not require all elements to be of the same size, **wl\_array\_for\_each()** does require all elements to have the same type and size.

## Member Function Documentation

### void \* wl\_array\_add (struct wl\_array \* array, size\_t size)

Increases the size of the array by size bytes.

**Parameters**

*array* Array whose size is to be increased \
 **size Number of bytes to increase the size of the array by**

**Returns**

**A pointer to the beginning of the newly appended space, or NULL when resizing fails.**

### int wl\_array\_copy (struct wl\_array \* array, struct wl\_array \* source)

**Copies the contents of** source **to** array**.**

**Parameters**

*array* **Destination array to copy to** \
 *source* **Source array to copy from**

**Returns**

**0 on success, or -1 on failure**

### void wl\_array\_init (struct wl\_array \* array)

**Initializes the array.**

**Parameters**

*array* **Array to initialize**

### void wl\_array\_release (struct wl\_array \* array)

**Releases the array data.**

**Note**

**Leaves the array in an invalid state.**

**Parameters**

*array* **Array whose data is to be released**

## Friends And Related Symbol Documentation

### #define wl\_array\_for\_each( pos, array) \[related\]

**Value:**

```
for (pos = (array)->data;                                       \
     (array)->size != 0 &&                                      \
     (const char *) pos < ((const char *) (array)->data + (array)->size); \
     (pos)++)
```

**Iterates over an array.**

**This macro expresses a for-each iterator for wl\_array. It assigns each element in the array to** pos**, which can then be referenced in a trailing code block.** pos **must be a pointer to the array element type, and all array elements must be of the same type and size.**

**Parameters**

*pos* **Cursor that each array element will be assigned to** \
 *array* **Array to iterate over**

**See also**

**wl\_list\_for\_each()**

## Field Documentation

### size\_t wl\_array::alloc

**Allocated space**

### void\* wl\_array::data

**Array data**

### size\_t wl\_array::size

**Array size**

## Author

**Generated automatically by Doxygen for Wayland from the source code.**
