

For this example we add stdlib.\+h, stdio.\+h and string.\+h for some convenience functions. The first thing to do to be able to use an \mbox{\hyperlink{group__Eina__Array__Group_ga2a57284ee83a7e767485b7ae2f5df86c}{Eina\+\_\+\+Array}} is to include \mbox{\hyperlink{Eina_8h}{Eina.\+h}}\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <stdio.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <string.h>}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <\mbox{\hyperlink{Eina_8h}{Eina.h}}>}}

\end{DoxyCodeInclude}
 Here we have a callback that prints the element given to it\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}}
\DoxyCodeLine{\_print(\textcolor{keyword}{const}\ \textcolor{keywordtype}{void}\ *container\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}},\ \textcolor{keywordtype}{void}\ *data,\ \textcolor{keywordtype}{void}\ *fdata\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ printf(\textcolor{stringliteral}{"{}\%s\(\backslash\)n"{}},\ (\textcolor{keywordtype}{char}\ *)data);}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}};}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 Now we create our entry point and declare some variables, nothing special\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keywordtype}{int}}
\DoxyCodeLine{main(\textcolor{keywordtype}{int}\ argc\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}},\ \textcolor{keywordtype}{char}\ **argv\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}*\ strings[]\ =\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \textcolor{stringliteral}{"{}helo"{}},\ \textcolor{stringliteral}{"{}hera"{}},\ \textcolor{stringliteral}{"{}starbuck"{}},\ \textcolor{stringliteral}{"{}kat"{}},\ \textcolor{stringliteral}{"{}boomer"{}},}
\DoxyCodeLine{\ \ \ \ \ \ \textcolor{stringliteral}{"{}hotdog"{}},\ \textcolor{stringliteral}{"{}longshot"{}},\ \textcolor{stringliteral}{"{}jammer"{}},\ \textcolor{stringliteral}{"{}crashdown"{}},\ \textcolor{stringliteral}{"{}hardball"{}},}
\DoxyCodeLine{\ \ \ \ \ \ \textcolor{stringliteral}{"{}duck"{}},\ \textcolor{stringliteral}{"{}racetrack"{}},\ \textcolor{stringliteral}{"{}apolo"{}},\ \textcolor{stringliteral}{"{}husker"{}},\ \textcolor{stringliteral}{"{}freaker"{}},}
\DoxyCodeLine{\ \ \ \ \ \ \textcolor{stringliteral}{"{}skulls"{}},\ \textcolor{stringliteral}{"{}bulldog"{}},\ \textcolor{stringliteral}{"{}flat\ top"{}},\ \textcolor{stringliteral}{"{}hammerhead"{}},\ \textcolor{stringliteral}{"{}gonzo"{}}}
\DoxyCodeLine{\ \ \ \};}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{struct__Eina__Array}{Eina\_Array}}\ *array;}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{int}\ i;}

\end{DoxyCodeInclude}
 Before we can start using any array function we need to initialize eina\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Main__Group_ga81b8137665b8a4d2cb38ca50017d4c74}{eina\_init}}();}

\end{DoxyCodeInclude}
 So now to actually create our array. The interesting thing here is the argument given to the \mbox{\hyperlink{group__Eina__Array__Group_gaf4b5844225b5359a617744210a5ed6ff}{eina\+\_\+array\+\_\+new()}} function. This argument sets how fast the array grows. 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ array\ =\ \mbox{\hyperlink{group__Eina__Array__Group_gaf4b5844225b5359a617744210a5ed6ff}{eina\_array\_new}}(10);}

\end{DoxyCodeInclude}
 If you know before hand how big the array will need to be you should set the step to that. In our case we can set it to the number of strings we have and since we didn\textquotesingle{}t do that in the \mbox{\hyperlink{group__Eina__Array__Group_gaf4b5844225b5359a617744210a5ed6ff}{eina\+\_\+array\+\_\+new()}} we can do it now\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Array__Group_ga9aefecc1767d6f793ea651a4e8c3d474}{eina\_array\_step\_set}}(array,\ \textcolor{keyword}{sizeof}(*array),\ 20);}

\end{DoxyCodeInclude}
 Now let us populate our array with some strings\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ 20;\ i++)}
\DoxyCodeLine{\ \ \ \ \ \mbox{\hyperlink{group__Eina__Array__Group_ga97ac1fe353f4cd7a9762af4d4db7b9c4}{eina\_array\_push}}(array,\ strdup(strings[i]));}

\end{DoxyCodeInclude}
\begin{DoxyNote}{Note}
Notice we use strdup, so we will have to free that memory later on.
\end{DoxyNote}
Now lets check the size of the array\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}array\ count:\ \%d\(\backslash\)n"{}},\ \mbox{\hyperlink{group__Eina__Array__Group_gafcc60b430bbc132114ef041e589d3ecf}{eina\_array\_count}}(array));}

\end{DoxyCodeInclude}
 And now we call a function on every member of our array to print it\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Array__Group_ga8de2d191a0fffceb5bdc6376540b8db1}{eina\_array\_foreach}}(array,\ \_print,\ NULL);}

\end{DoxyCodeInclude}
 One of the strengths of \mbox{\hyperlink{group__Eina__Array__Group_ga2a57284ee83a7e767485b7ae2f5df86c}{Eina\+\_\+\+Array}} over \mbox{\hyperlink{group__Eina__List__Group_ga3295e1210efea1fb0fd6acbf3cbc1f29}{Eina\+\_\+\+List}} is that it has very fast random access to elements, so this is very efficient\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}Top\ gun:\ \%s\(\backslash\)n"{}},\ (\textcolor{keywordtype}{char}*)\mbox{\hyperlink{group__Eina__Array__Group_gae4a12746bff6643605953de2c47f2d02}{eina\_array\_data\_get}}(array,\ 2));}

\end{DoxyCodeInclude}
 And now we free up the memory allocated with the strdup()s\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{while}\ (\mbox{\hyperlink{group__Eina__Array__Group_gafcc60b430bbc132114ef041e589d3ecf}{eina\_array\_count}}(array))}
\DoxyCodeLine{\ \ \ \ \ free(\mbox{\hyperlink{group__Eina__Array__Group_ga329683a8ccfa53ecfc70f04d7f471560}{eina\_array\_pop}}(array));}

\end{DoxyCodeInclude}
 And the array memory itself\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Array__Group_ga7fa7e2cdcfb739140d5c5a5044086ce1}{eina\_array\_free}}(array);}

\end{DoxyCodeInclude}
 And finally shutdown eina and exit\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Main__Group_ga5bf35513199d5220341437c05696285d}{eina\_shutdown}}();}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 The full source code can be found in the examples folder in the \mbox{\hyperlink{eina_array_01_c}{eina\+\_\+array\+\_\+01.c}} file. 