1array(3)                   Library Functions Manual                   array(3)
2
3
4

NAME

6       array - The array library interface
7

SYNTAX

9       #include <array.h>
10
11

DESCRIPTION

13       An allocated array variable keeps track of
14
15
16
17       ·      a (nonzero) pointer to a dynamically allocated region of memory;
18
19       ·      the number of bytes allocated (always positive); and
20
21       ·      the  number  of  bytes  initialized (between 0 and the number of
22              bytes allocated).
23
24       There are two other possibilities for the state of an  array  variable:
25       unallocated  and  failed.  In both cases, there is no dynamically allo‐
26       cated region of memory.
27
28       A new array variable is normally created as a static variable:
29
30         #include "array.h"
31
32         static array x;
33
34       At this point it is unallocated.  The array  library  provides  various
35       allocation and inspection functions.
36
37       A  new  array variable can also be created dynamically. It must be ini‐
38       tialized to all-0, meaning unallocated, before it is given  to  any  of
39       the array functions. It must be returned to the unallocated (or failed)
40       state, for example with array_reset,  before  it  is  destroyed.  These
41       rules prevent all memory leaks.
42

Expansion and inspection

44         array x;
45
46         t* p1 = array_allocate(&x,sizeof(t),pos);
47
48         t* p2 = array_get(&x,sizeof(t),pos);
49
50         t* p3 = array_start(&x);
51
52         int64 len = array_length(&x,sizeof(t));
53
54         int64 bytes = array_bytes(&x);
55
56

Truncation and deallocation

58         array x;
59
60         array_truncate(&x,sizeof(t),len);
61
62         array_trunc(&x);
63
64         array_reset(&x);
65
66         array_fail(&x);
67
68

Comparison

70         array x;
71         array y;
72
73         if (array_equal(&x,&y))
74           /* arrays are equal... */
75
76

Concatenation

78         array x;
79         array y;
80
81         array_cat(&x,&y);
82
83         array_catb(&x,"fnord",5);
84
85         array_cats(&x,"fnord");
86
87         array_cats0(&x,"fnord"); /* also append the \0 */
88
89         array_cat0(&x); /* append \0 */
90
91         array_cate(&x,"fnord",1,4); /* append "nor" */
92
93

ORIGINAL API DEFINITION

95       http://cr.yp.to/lib/array.html
96

SEE ALSO

98       array_get(3), array_start(3), array_fail(3)
99
100
101
102                                                                      array(3)
Impressum