A real life example is usually the best way to see how things are used, but they also involve a lot more code than what needs to be shown, so instead of going that way, we\textquotesingle{}ll be borrowing some pieces from one in the following example.

It\textquotesingle{}s been slightly modified from the original source to show more of the varied ways in which Eet can handle our data.

\mbox{\hyperlink{eet-data-file_descriptor_01_8c-example}{This example}} shows a cache of user accounts and messages received, and it\textquotesingle{}s a bit more interactive than previous examples.

Let\textquotesingle{}s begin by looking at the structures we\textquotesingle{}ll be using. First we have one to define the messages the user receives and one for the one he posts. Straight forward and nothing new here.  
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{keyword}{typedef}\ \textcolor{keyword}{struct}}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ \ *screen\_name;}
\DoxyCodeLine{\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ \ *name;}
\DoxyCodeLine{\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ \ *message;}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{int}\ id;}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{int}\ status\_id;}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{int}\ date;}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{int}\ timeline;}
\DoxyCodeLine{\}\ My\_Message;}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{typedef}\ \textcolor{keyword}{struct}}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *dm\_to;}
\DoxyCodeLine{\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *message;}
\DoxyCodeLine{\}\ My\_Post;}

\end{DoxyCodeInclude}
 One more to declare the account itself. This one will contain a list of all messages received, and the posts we make ourselves will be kept in an array. No special reason other than to show how to use arrays with Eet. 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{typedef}\ \textcolor{keyword}{struct}}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{int}\ id;}
\DoxyCodeLine{\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ \ *name;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{struct__Eina__List}{Eina\_List}}\ \ \ *messages;}
\DoxyCodeLine{\ \ \ My\_Post\ \ \ \ \ *posts;}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{int}\ \ \ \ \ \ \ \ \ \ posts\_count;}
\DoxyCodeLine{\}\ My\_Account;}

\end{DoxyCodeInclude}
 Finally, the main structure to hold our cache of accounts. We\textquotesingle{}ll be looking for these accounts by their names, so let\textquotesingle{}s keep them in a hash, using that name as the key. 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{typedef}\ \textcolor{keyword}{struct}}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{int}\ version;\ \textcolor{comment}{//\ it\ is\ recommended\ to\ use\ versioned\ configuration!}}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Hash__Group_ga9a89d7d3ee260d3a60572ebf651b07e0}{Eina\_Hash}}\ \ \ *accounts;}
\DoxyCodeLine{\}\ My\_Cache;}

\end{DoxyCodeInclude}
 As explained before, we need one descriptor for each struct we want Eet to handle, but this time we also want to keep around our Eet file and its string dictionary. You will see why in a moment. 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{keyword}{static}\ \mbox{\hyperlink{group__Eet__Data__Group_ga4baec0e840012480a0958c5c3bca276d}{Eet\_Data\_Descriptor}}\ *\_my\_cache\_descriptor;}
\DoxyCodeLine{\textcolor{keyword}{static}\ \mbox{\hyperlink{group__Eet__Data__Group_ga4baec0e840012480a0958c5c3bca276d}{Eet\_Data\_Descriptor}}\ *\_my\_account\_descriptor;}
\DoxyCodeLine{\textcolor{keyword}{static}\ \mbox{\hyperlink{group__Eet__Data__Group_ga4baec0e840012480a0958c5c3bca276d}{Eet\_Data\_Descriptor}}\ *\_my\_message\_descriptor;}
\DoxyCodeLine{\textcolor{keyword}{static}\ \mbox{\hyperlink{group__Eet__Data__Group_ga4baec0e840012480a0958c5c3bca276d}{Eet\_Data\_Descriptor}}\ *\_my\_post\_descriptor;}
\DoxyCodeLine{\textcolor{keyword}{static}\ \mbox{\hyperlink{group__Eet__File__Group_ga8d9779184a9870c1a225f1f40c76e8a7}{Eet\_File}}\ *\_my\_cache\_file\ =\ NULL;}
\DoxyCodeLine{\textcolor{keyword}{static}\ \mbox{\hyperlink{group__Eet__File__Group_gaf0984c8280699ca5a3c4966f5580324c}{Eet\_Dictionary}}\ *\_my\_cache\_dict\ =\ NULL;}

\end{DoxyCodeInclude}
 The differences begin now. They aren\textquotesingle{}t much, but we\textquotesingle{}ll be creating our descriptors differently. Things can be added to our cache, but we won\textquotesingle{}t be modifying the current contents, so we can consider the data read from it to be read-\/only, and thus allow Eet to save time and memory by not duplicating thins unnecessary. 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{\_my\_cache\_descriptor\_init(\textcolor{keywordtype}{void})}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{struct__Eet__Data__Descriptor__Class}{Eet\_Data\_Descriptor\_Class}}\ eddc;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{//\ The\ FILE\ variant\ is\ good\ for\ caches\ and\ things\ that\ are\ just}}
\DoxyCodeLine{\ \ \ \textcolor{comment}{//\ appended,\ but\ needs\ to\ take\ care\ when\ changing\ strings\ and\ files\ must}}
\DoxyCodeLine{\ \ \ \textcolor{comment}{//\ be\ kept\ open\ so\ mmap()ed\ strings\ will\ be\ kept\ alive.}}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eet__Data__Group_ga0bf94c07d8e69cfaac8dd2d615d7542c}{EET\_EINA\_FILE\_DATA\_DESCRIPTOR\_CLASS\_SET}}(\&eddc,\ My\_Cache);}
\DoxyCodeLine{\ \ \ \_my\_cache\_descriptor\ =\ \mbox{\hyperlink{group__Eet__Data__Group_gaa613c638dfb72d3f9bd2bd1d4c1bf844}{eet\_data\_descriptor\_file\_new}}(\&eddc);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eet__Data__Group_ga0bf94c07d8e69cfaac8dd2d615d7542c}{EET\_EINA\_FILE\_DATA\_DESCRIPTOR\_CLASS\_SET}}(\&eddc,\ My\_Account);}
\DoxyCodeLine{\ \ \ \_my\_account\_descriptor\ =\ \mbox{\hyperlink{group__Eet__Data__Group_gaa613c638dfb72d3f9bd2bd1d4c1bf844}{eet\_data\_descriptor\_file\_new}}(\&eddc);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eet__Data__Group_ga0bf94c07d8e69cfaac8dd2d615d7542c}{EET\_EINA\_FILE\_DATA\_DESCRIPTOR\_CLASS\_SET}}(\&eddc,\ My\_Message);}
\DoxyCodeLine{\ \ \ \_my\_message\_descriptor\ =\ \mbox{\hyperlink{group__Eet__Data__Group_gaa613c638dfb72d3f9bd2bd1d4c1bf844}{eet\_data\_descriptor\_file\_new}}(\&eddc);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eet__Data__Group_ga0bf94c07d8e69cfaac8dd2d615d7542c}{EET\_EINA\_FILE\_DATA\_DESCRIPTOR\_CLASS\_SET}}(\&eddc,\ My\_Post);}
\DoxyCodeLine{\ \ \ \_my\_post\_descriptor\ =\ \mbox{\hyperlink{group__Eet__Data__Group_gaa613c638dfb72d3f9bd2bd1d4c1bf844}{eet\_data\_descriptor\_file\_new}}(\&eddc);}

\end{DoxyCodeInclude}
 As the comment in the code explains, we are asking Eet to give us strings directly from the mapped file, which avoids having to load it in memory and data duplication. Of course, there are things to take into account when doing things this way, and they will be mentioned as we encounter those special cases.

Next comes the actual description of our data, just like we did in the previous examples. 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{preprocessor}{\#define\ ADD\_BASIC(member,\ eet\_type)\ \(\backslash\)}}
\DoxyCodeLine{\textcolor{preprocessor}{\ \ EET\_DATA\_DESCRIPTOR\_ADD\_BASIC\ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{\textcolor{preprocessor}{\ \ \ \ (\_my\_message\_descriptor,\ My\_Message,\ \#\ member,\ member,\ eet\_type)}}
\DoxyCodeLine{\ \ \ ADD\_BASIC(screen\_name,\ \mbox{\hyperlink{group__Eet__Data__Group_ga0d2cf409bf3f151156d74d18ac59e3d1}{EET\_T\_STRING}});}
\DoxyCodeLine{\ \ \ ADD\_BASIC(name,\ \mbox{\hyperlink{group__Eet__Data__Group_ga0d2cf409bf3f151156d74d18ac59e3d1}{EET\_T\_STRING}});}
\DoxyCodeLine{\ \ \ ADD\_BASIC(message,\ \mbox{\hyperlink{group__Eet__Data__Group_ga0d2cf409bf3f151156d74d18ac59e3d1}{EET\_T\_STRING}});}
\DoxyCodeLine{\ \ \ ADD\_BASIC(\textcolor{keywordtype}{id},\ \mbox{\hyperlink{group__Eet__Data__Group_gacf6a3c9f06e10e20be5b02cd8c6a220b}{EET\_T\_UINT}});}
\DoxyCodeLine{\ \ \ ADD\_BASIC(status\_id,\ \mbox{\hyperlink{group__Eet__Data__Group_gacf6a3c9f06e10e20be5b02cd8c6a220b}{EET\_T\_UINT}});}
\DoxyCodeLine{\ \ \ ADD\_BASIC(date,\ \mbox{\hyperlink{group__Eet__Data__Group_gacf6a3c9f06e10e20be5b02cd8c6a220b}{EET\_T\_UINT}});}
\DoxyCodeLine{\ \ \ ADD\_BASIC(timeline,\ \mbox{\hyperlink{group__Eet__Data__Group_gacf6a3c9f06e10e20be5b02cd8c6a220b}{EET\_T\_UINT}});}
\DoxyCodeLine{\textcolor{preprocessor}{\#undef\ ADD\_BASIC}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#define\ ADD\_BASIC(member,\ eet\_type)\ \(\backslash\)}}
\DoxyCodeLine{\ \ \mbox{\hyperlink{group__Eet__Data__Group_gac38ce778d7eba37cfca8a19efb7a9b3a}{EET\_DATA\_DESCRIPTOR\_ADD\_BASIC}}\ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{\ \ \ \ (\_my\_post\_descriptor,\ My\_Post,\ \#\ member,\ member,\ eet\_type)}
\DoxyCodeLine{\ \ \ ADD\_BASIC(dm\_to,\ \mbox{\hyperlink{group__Eet__Data__Group_ga0d2cf409bf3f151156d74d18ac59e3d1}{EET\_T\_STRING}});}
\DoxyCodeLine{\ \ \ ADD\_BASIC(message,\ \mbox{\hyperlink{group__Eet__Data__Group_ga0d2cf409bf3f151156d74d18ac59e3d1}{EET\_T\_STRING}});}
\DoxyCodeLine{\textcolor{preprocessor}{\#undef\ ADD\_BASIC}}

\end{DoxyCodeInclude}
 And the account struct\textquotesingle{}s description doesn\textquotesingle{}t add much new, but it\textquotesingle{}s worth commenting on it. 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{preprocessor}{\#define\ ADD\_BASIC(member,\ eet\_type)\ \(\backslash\)}}
\DoxyCodeLine{\textcolor{preprocessor}{\ \ EET\_DATA\_DESCRIPTOR\_ADD\_BASIC\ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{\textcolor{preprocessor}{\ \ \ \ (\_my\_account\_descriptor,\ My\_Account,\ \#\ member,\ member,\ eet\_type)}}
\DoxyCodeLine{\ \ \ ADD\_BASIC(name,\ \mbox{\hyperlink{group__Eet__Data__Group_ga0d2cf409bf3f151156d74d18ac59e3d1}{EET\_T\_STRING}});}
\DoxyCodeLine{\ \ \ ADD\_BASIC(\textcolor{keywordtype}{id},\ \mbox{\hyperlink{group__Eet__Data__Group_gacf6a3c9f06e10e20be5b02cd8c6a220b}{EET\_T\_UINT}});}
\DoxyCodeLine{\textcolor{preprocessor}{\#undef\ ADD\_BASIC}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eet__Data__Group_gabb4c7833ba053f2322e6b667a9ec7f04}{EET\_DATA\_DESCRIPTOR\_ADD\_LIST}}}
\DoxyCodeLine{\ \ \ \ \ (\_my\_account\_descriptor,\ My\_Account,\ \textcolor{stringliteral}{"{}messages"{}},\ messages,}
\DoxyCodeLine{\ \ \ \ \ \_my\_message\_descriptor);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eet__Data__Group_ga7adad32d2eba76566533353632f00ae4}{EET\_DATA\_DESCRIPTOR\_ADD\_VAR\_ARRAY}}}
\DoxyCodeLine{\ \ \ \ \ (\_my\_account\_descriptor,\ My\_Account,\ \textcolor{stringliteral}{"{}posts"{}},\ posts,}
\DoxyCodeLine{\ \ \ \ \ \_my\_post\_descriptor);}

\end{DoxyCodeInclude}
 How to add a list we\textquotesingle{}ve seen before, but now we are also adding an array. There\textquotesingle{}s nothing really special about it, but it\textquotesingle{}s important to note that the EET\+\_\+\+DATA\+\_\+\+DESCRIPTOR\+\_\+\+ADD\+\_\+\+VAR\+\_\+\+ARRAY is used to add arrays of variable length to a descriptor. That is, arrays just like the one we defined. Since there\textquotesingle{}s no way in C to know how long they are, we need to keep track of the count ourselves and Eet needs to know how to do so as well. That\textquotesingle{}s what the {\ttfamily posts\+\_\+count} member of our struct is for. When adding our array member, this macro will look for another variable in the struct named just like the array, but with {\ttfamily \+\_\+count} attached to the end. When saving our data, Eet will know how many elements the array contains by looking into this count variable. When loading back from a file, this variable will be set to the right number of elements.

Another option for arrays is to use EET\+\_\+\+DATA\+\_\+\+DESCRIPTOR\+\_\+\+ADD\+\_\+\+ARRAY, which takes care of fixed sized arrays. For example, let\textquotesingle{}s suppose that we want to keep track of only the last ten posts the user sent, and we declare our account struct as follows 
\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keyword}{typedef}\ \textcolor{keyword}{struct}}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{int}\ id;}
\DoxyCodeLine{\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ \ *name;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{struct__Eina__List}{Eina\_List}}\ \ \ *messages;}
\DoxyCodeLine{\ \ \ My\_Post\ \ \ \ \ \ posts[10];}
\DoxyCodeLine{\}\ My\_Account;}

\end{DoxyCode}
 Then we would add the array to our descriptor with 
\begin{DoxyCode}{0}
\DoxyCodeLine{\mbox{\hyperlink{group__Eet__Data__Group_gabc903baa4d5dc50a98f5e1a68d66fd2b}{EET\_DATA\_DESCRIPTOR\_ADD\_ARRAY}}(\_my\_account\_descriptor,\ My\_Account,\ \textcolor{stringliteral}{"{}posts"{}},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ posts,\ \_my\_post\_descriptor);}

\end{DoxyCode}


Notice how this time we don\textquotesingle{}t have a {\ttfamily posts\+\_\+count} variable in our struct. We could have it for the program to keep track of how many posts the array actually contains, but Eet no longer needs it. Being defined that way the array is already taking up all the memory needed for the ten elements, and it is possible in C to determine how much it is in code. When saving our data, Eet will just dump the entire memory blob into the file, regardless of how much of it is really used. So it\textquotesingle{}s important to take into consideration this kind of things when defining your data types. Each has its uses, its advantages and disadvantages and it\textquotesingle{}s up to you to decide which to use.

Now, going back to our example, we have to finish adding our data to the descriptors. We are only missing the main one for the cache, which contains our hash of accounts. Unless you are using your own hash functions when setting the descriptor class, always use hashes with string type keys. 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{preprocessor}{\#define\ ADD\_BASIC(member,\ eet\_type)\ \(\backslash\)}}
\DoxyCodeLine{\textcolor{preprocessor}{\ \ EET\_DATA\_DESCRIPTOR\_ADD\_BASIC\ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{\textcolor{preprocessor}{\ \ \ \ (\_my\_cache\_descriptor,\ My\_Cache,\ \#\ member,\ member,\ eet\_type)}}
\DoxyCodeLine{\ \ \ ADD\_BASIC(version,\ \mbox{\hyperlink{group__Eet__Data__Group_gacf6a3c9f06e10e20be5b02cd8c6a220b}{EET\_T\_UINT}});}
\DoxyCodeLine{\textcolor{preprocessor}{\#undef\ ADD\_BASIC}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eet__Data__Group_gad5e348ead4ba0b441c1e020f9bf23365}{EET\_DATA\_DESCRIPTOR\_ADD\_HASH}}}
\DoxyCodeLine{\ \ \ \ \ (\_my\_cache\_descriptor,\ My\_Cache,\ \textcolor{stringliteral}{"{}accounts"{}},\ accounts,}
\DoxyCodeLine{\ \ \ \ \ \_my\_account\_descriptor);}
\DoxyCodeLine{\}\ \textcolor{comment}{/*\ \_my\_cache\_descriptor\_init\ */}}

\end{DoxyCodeInclude}
 If you remember, we told Eet not to duplicate memory when possible at the time of loading back our data. But this doesn\textquotesingle{}t mean everything will be loaded straight from disk and we don\textquotesingle{}t have to worry about freeing it. Data in the Eet file is compressed and encoded, so it still needs to be decoded and memory will be allocated to convert it back into something we can use. We also need to take care of anything we add in the current instance of the program. To summarize, any string we get from Eet is likely to be a pointer to the internal dictionary, and trying to free it will, in the best case, crash our application right away.

So how do we know if we have to free a string? We check if it\textquotesingle{}s part of the dictionary, and if it\textquotesingle{}s not there we can be sure it\textquotesingle{}s safe to get rid of it. 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{\_eet\_string\_free(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *str)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (!str)}
\DoxyCodeLine{\ \ \ \ \ \textcolor{keywordflow}{return};}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ ((\_my\_cache\_dict)\ \&\&\ (\mbox{\hyperlink{group__Eet__File__Group_ga53290da52edb929b85e51f25e79d27c8}{eet\_dictionary\_string\_check}}(\_my\_cache\_dict,\ str)))}
\DoxyCodeLine{\ \ \ \ \ \textcolor{keywordflow}{return};}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Stringshare__Group_ga5538b4a134987b8a01744fad1a845ba4}{eina\_stringshare\_del}}(str);}
\DoxyCodeLine{\}\ \textcolor{comment}{/*\ \_eet\_string\_free\ */}}

\end{DoxyCodeInclude}
 See how this is used when adding a new message to our cache. 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{keyword}{static}\ My\_Message\ *}
\DoxyCodeLine{\_my\_message\_new(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *message)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ My\_Message\ *msg\ =\ calloc(1,\ \textcolor{keyword}{sizeof}(My\_Message));}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (!msg)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}ERROR:\ could\ not\ calloc\ My\_Message\(\backslash\)n"{}});}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ msg-\/>message\ =\ \mbox{\hyperlink{group__Eina__Stringshare__Group_ga4e3ce40744291c1fb8574e26883c0bf2}{eina\_stringshare\_add}}(message);}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ msg;}
\DoxyCodeLine{\}\ \textcolor{comment}{/*\ \_my\_message\_new\ */}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{\_my\_message\_free(My\_Message\ *msg)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \_eet\_string\_free(msg-\/>screen\_name);}
\DoxyCodeLine{\ \ \ \_eet\_string\_free(msg-\/>name);}
\DoxyCodeLine{\ \ \ \_eet\_string\_free(msg-\/>message);}
\DoxyCodeLine{\ \ \ free(msg);}
\DoxyCodeLine{\}\ \textcolor{comment}{/*\ \_my\_message\_free\ */}}

\end{DoxyCodeInclude}
 Skipping all the utility functions used by our program (remember you can look at the full example \mbox{\hyperlink{eet-data-file_descriptor_01_8c-example}{here}}) we get to our cache loading code. Nothing out of the ordinary at first, just the same old open file, read data using our main descriptor to decode it into something we can use and check version of loaded data and if it doesn\textquotesingle{}t match, do something accordingly. 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{keyword}{static}\ My\_Cache\ *}
\DoxyCodeLine{\_my\_cache\_new(\textcolor{keywordtype}{void})}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ My\_Cache\ *my\_cache\ =\ calloc(1,\ \textcolor{keyword}{sizeof}(My\_Cache));}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (!my\_cache)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}ERROR:\ could\ not\ calloc\ My\_Cache\(\backslash\)n"{}});}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ NULL;}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ my\_cache-\/>accounts\ =\ \mbox{\hyperlink{group__Eina__Hash__Group_ga96bbbf394fb34d7e1f57d261de638e69}{eina\_hash\_string\_small\_new}}(NULL);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ my\_cache-\/>version\ =\ 1;}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ my\_cache;}
\DoxyCodeLine{\}\ \textcolor{comment}{/*\ \_my\_cache\_new\ */}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}}
\DoxyCodeLine{\_my\_cache\_account\_free\_cb(\textcolor{keyword}{const}\ \mbox{\hyperlink{group__Eina__Hash__Group_ga9a89d7d3ee260d3a60572ebf651b07e0}{Eina\_Hash}}\ *hash\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{void}\ \ \ \ \ \ *key\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{void}\ \ \ \ \ \ \ \ \ \ \ \ *data,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{void}\ \ \ \ \ \ \ \ \ \ \ \ *fdata\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \_my\_account\_free(data);}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}};}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 Then comes the interesting part. Remember how we kept two more global variables with our descriptors? One of them we already used to check if it was right to free a string or not, but we didn\textquotesingle{}t know where it came from. Loading our data straight from the mmapped file means that we can\textquotesingle{}t close it until we are done using it, so we need to keep its handler around until then. It also means that any changes done to the file can, and will, invalidate all our pointers to the file backed data, so if we add something and save the file, we need to reload our cache.

Thus our load function checks if we had an open file, if there is it gets closed and our variable is updated to the new handler. Then we get the string dictionary we use to check if a string is part of it or not. Updating any references to the cache data is up you as a programmer to handle properly, there\textquotesingle{}s nothing Eet can do in this situation. 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{\_my\_cache\_free(My\_Cache\ *my\_cache)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Hash__Group_ga9237dbade8e59ac827992c7a5146cb20}{eina\_hash\_foreach}}(my\_cache-\/>accounts,\ \_my\_cache\_account\_free\_cb,\ NULL);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Hash__Group_ga76829f09c99852b1536efc813d99fc78}{eina\_hash\_free}}(my\_cache-\/>accounts);}
\DoxyCodeLine{\ \ \ free(my\_cache);}
\DoxyCodeLine{\}\ \textcolor{comment}{/*\ \_my\_cache\_free\ */}}

\end{DoxyCodeInclude}
 The save function doesn\textquotesingle{}t have anything new, and all that\textquotesingle{}s left after it is the main program, which doesn\textquotesingle{}t really have anything of interest within the scope of what we are learning. 