

This example creates an inline array of chars, adds some elements, prints them, re-\/purposes the array to store ints, adds some elements and prints that.

We are going to start with a function to compare ints. We need this because the \textquotesingle{}\texorpdfstring{$>$}{>}\textquotesingle{} operator is not a function and can\textquotesingle{}t be used where Eina\+\_\+\+Compare\+\_\+\+Cb is needed. 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{keywordtype}{int}}
\DoxyCodeLine{cmp(\textcolor{keyword}{const}\ \textcolor{keywordtype}{void}\ *a,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{void}\ *b)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ *(\textcolor{keywordtype}{int}*)a\ >\ *(\textcolor{keywordtype}{int}*)b;}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 And then move on to the code we actually care about, starting with variable declarations and eina initialization\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keywordtype}{int}\ 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{\ \ \ \mbox{\hyperlink{struct__Eina__Inarray}{Eina\_Inarray}}\ *iarr;}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{char}\ ch,\ *ch2;}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{int}\ a,\ *b;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Main__Group_ga81b8137665b8a4d2cb38ca50017d4c74}{eina\_init}}();}

\end{DoxyCodeInclude}
 Creating an inline array is very simple, we just need to know what type we want to store\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ iarr\ =\ \mbox{\hyperlink{group__Eina__Inline__Array__Group_gab90ef5e018c9e18341d5057254fd2f5b}{eina\_inarray\_new}}(\textcolor{keyword}{sizeof}(\textcolor{keywordtype}{char}),\ 0);}

\end{DoxyCodeInclude}
\begin{DoxyNote}{Note}
The second parameter(the step) is left at zero which means that eina chooses an appropriate value, this should {\bfseries{only}} be changed if it\textquotesingle{}s known, beforehand, that how many elements the array has.
\end{DoxyNote}
Once we have an array we can start adding elements to it. Because the insertion function expects a memory address we have to put the value we want to store in a variable (this should be no problem since in the real world usage that\textquotesingle{}s usually where the value is anyways)\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ ch\ =\ \textcolor{charliteral}{'a'};}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Inline__Array__Group_ga1546c690e7e63307af20f7ac3db1b095}{eina\_inarray\_push}}(iarr,\ \&ch);}

\end{DoxyCodeInclude}
\begin{DoxyNote}{Note}
Because the inline array copies the value given to it we can later change {\ttfamily ch}, which we do, without affecting the contents of the array.
\end{DoxyNote}
So let\textquotesingle{}s add some more elements\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ ch\ =\ \textcolor{charliteral}{'b'};}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Inline__Array__Group_ga1546c690e7e63307af20f7ac3db1b095}{eina\_inarray\_push}}(iarr,\ \&ch);}
\DoxyCodeLine{\ \ \ ch\ =\ \textcolor{charliteral}{'c'};}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Inline__Array__Group_ga1546c690e7e63307af20f7ac3db1b095}{eina\_inarray\_push}}(iarr,\ \&ch);}
\DoxyCodeLine{\ \ \ ch\ =\ \textcolor{charliteral}{'d'};}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Inline__Array__Group_ga1546c690e7e63307af20f7ac3db1b095}{eina\_inarray\_push}}(iarr,\ \&ch);}

\end{DoxyCodeInclude}
 We then iterate over our array and print every position of it. The thing to note here is not so much the values, which are the expected \textquotesingle{}a\textquotesingle{}, \textquotesingle{}b\textquotesingle{}, \textquotesingle{}c\textquotesingle{}, and \textquotesingle{}d\textquotesingle{}, but rather the memory address of these values, they are sequential\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}Inline\ array\ of\ chars:\(\backslash\)n"{}});}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Inline__Array__Group_gab6ffcad27b5099aa34af9ecd5e2b22f9}{EINA\_INARRAY\_FOREACH}}(iarr,\ ch2)}
\DoxyCodeLine{\ \ \ \ \ printf(\textcolor{stringliteral}{"{}char:\ \%c(pointer:\ \%p)\(\backslash\)n"{}},\ *ch2,\ ch2);}

\end{DoxyCodeInclude}
 We are now going to use our array to store ints, so we need to first erase every member currently on the array\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Inline__Array__Group_ga3adeb0e441f32ab67ec498964826aaf0}{eina\_inarray\_flush}}(iarr);}

\end{DoxyCodeInclude}
 And then to be able to store a different type on the same array, we use the \mbox{\hyperlink{group__Eina__Inline__Array__Group_gaf21d934d2af2fd7872187db4f4dd52cf}{eina\+\_\+inarray\+\_\+step\+\_\+set()}} function, which is just like the \mbox{\hyperlink{group__Eina__Inline__Array__Group_gab90ef5e018c9e18341d5057254fd2f5b}{eina\+\_\+inarray\+\_\+new()}} function except it receives an already allocated memory. This time we\textquotesingle{}re going to ask eina to use a step of size 4 because that\textquotesingle{}s how many elements we are going to put in the array\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Inline__Array__Group_gaf21d934d2af2fd7872187db4f4dd52cf}{eina\_inarray\_step\_set}}(iarr,\ \textcolor{keyword}{sizeof}(\mbox{\hyperlink{struct__Eina__Inarray}{Eina\_Inarray}}),\ \textcolor{keyword}{sizeof}(\textcolor{keywordtype}{int}),\ 4);}

\end{DoxyCodeInclude}
\begin{DoxyNote}{Note}
Strictly speaking the reason to call \mbox{\hyperlink{group__Eina__Inline__Array__Group_gaf21d934d2af2fd7872187db4f4dd52cf}{eina\+\_\+inarray\+\_\+step\+\_\+set()}} is not because we\textquotesingle{}re storing a different type, but because our types have different sizes. Eina inline arrays don\textquotesingle{}t actually know anything about types, they only deal with blocks of memory of a given size. 

Since \mbox{\hyperlink{group__Eina__Inline__Array__Group_gaf21d934d2af2fd7872187db4f4dd52cf}{eina\+\_\+inarray\+\_\+step\+\_\+set()}} receives already allocated memory, you can (and it is in fact a good practice) use inline arrays that are not declared as pointers\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{\mbox{\hyperlink{struct__Eina__Inarray}{Eina\_Inarray}}\ arr;}
\DoxyCodeLine{\mbox{\hyperlink{group__Eina__Inline__Array__Group_gaf21d934d2af2fd7872187db4f4dd52cf}{eina\_inarray\_step\_set}}(\&arr,\ \textcolor{keyword}{sizeof}(arr),\ \textcolor{keyword}{sizeof}(\textcolor{keywordtype}{int}),\ 4);}

\end{DoxyCode}

\end{DoxyNote}
And now to add our integer values to the array\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ a\ =\ 97;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Inline__Array__Group_ga1546c690e7e63307af20f7ac3db1b095}{eina\_inarray\_push}}(iarr,\ \&a);}
\DoxyCodeLine{\ \ \ a\ =\ 98;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Inline__Array__Group_ga1546c690e7e63307af20f7ac3db1b095}{eina\_inarray\_push}}(iarr,\ \&a);}
\DoxyCodeLine{\ \ \ a\ =\ 100;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Inline__Array__Group_ga1546c690e7e63307af20f7ac3db1b095}{eina\_inarray\_push}}(iarr,\ \&a);}

\end{DoxyCodeInclude}
 Just to change things up a bit we\textquotesingle{}ve left out the 99 value, but we still add it in such a way that it keeps the array ordered. There are many ways to do this, we could use \mbox{\hyperlink{group__Eina__Inline__Array__Group_ga81ce838167d5a77d727ff8530371c445}{eina\+\_\+inarray\+\_\+insert\+\_\+at()}}, or we could change the value of the last member using \mbox{\hyperlink{group__Eina__Inline__Array__Group_ga8bd6697888c2fe29b25414663e8d1890}{eina\+\_\+inarray\+\_\+replace\+\_\+at()}} and then append the values in the right order, but for no particular reason we\textquotesingle{}re going to use \mbox{\hyperlink{group__Eina__Inline__Array__Group_ga8fb844f63ddda56260624756942d3e6e}{eina\+\_\+inarray\+\_\+insert\+\_\+sorted()}} instead\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ a\ =\ 99;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Inline__Array__Group_ga8fb844f63ddda56260624756942d3e6e}{eina\_inarray\_insert\_sorted}}(iarr,\ \&a,\ cmp);}

\end{DoxyCodeInclude}
 We then print the size of our array, and the array itself, much like last time the values are not surprising, and neither should it be that the memory addresses are contiguous\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}Inline\ array\ of\ integers\ with\ \%d\ elements:\(\backslash\)n"{}},\ \mbox{\hyperlink{group__Eina__Inline__Array__Group_ga63333e28eaa59cf00bc748b3df55bad7}{eina\_inarray\_count}}(iarr));}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Inline__Array__Group_gab6ffcad27b5099aa34af9ecd5e2b22f9}{EINA\_INARRAY\_FOREACH}}(iarr,\ b)}
\DoxyCodeLine{\ \ \ \ \ printf(\textcolor{stringliteral}{"{}int:\ \%d(pointer:\ \%p)\(\backslash\)n"{}},\ *b,\ b);}

\end{DoxyCodeInclude}
 Once done we free our array and shutdown eina\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Inline__Array__Group_ga030924ac7ef1ce357b328e4a40e5f77f}{eina\_inarray\_free}}(iarr);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Main__Group_ga5bf35513199d5220341437c05696285d}{eina\_shutdown}}();}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 The source for this example\+: \mbox{\hyperlink{eina_inarray_01_c}{eina\+\_\+inarray\+\_\+01.\+c}} 