\hypertarget{a00848_source}{}\doxysection{AAX\+\_\+\+Alignment.\+h}
\label{a00848_source}\index{AAX\_Alignment.h@{AAX\_Alignment.h}}
\mbox{\hyperlink{a00848}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{comment}{/*================================================================================================*/}}
\DoxyCodeLine{00002\ \textcolor{comment}{/*}}
\DoxyCodeLine{00003\ \textcolor{comment}{\ *\ \ Copyright\ 2009-\/2015,\ 2023\ Avid\ Technology,\ Inc.}}
\DoxyCodeLine{00004\ \textcolor{comment}{\ *\ \ All\ rights\ reserved.}}
\DoxyCodeLine{00005\ \textcolor{comment}{\ *\ \ }}
\DoxyCodeLine{00006\ \textcolor{comment}{\ *\ \ CONFIDENTIAL:\ this\ document\ contains\ confidential\ information\ of\ Avid.\ Do}}
\DoxyCodeLine{00007\ \textcolor{comment}{\ *\ \ not\ disclose\ to\ any\ third\ party.\ Use\ of\ the\ information\ contained\ in\ this}}
\DoxyCodeLine{00008\ \textcolor{comment}{\ *\ \ document\ is\ subject\ to\ an\ Avid\ SDK\ license.}}
\DoxyCodeLine{00009\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00010\ }
\DoxyCodeLine{00017\ \textcolor{comment}{/*================================================================================================*/}}
\DoxyCodeLine{00018\ }
\DoxyCodeLine{00019\ \textcolor{preprocessor}{\#ifndef\ AAX\_ALIGNMENT\_H}}
\DoxyCodeLine{00020\ \textcolor{preprocessor}{\#define\ AAX\_ALIGNMENT\_H}}
\DoxyCodeLine{00021\ }
\DoxyCodeLine{00022\ \textcolor{preprocessor}{\#include\ <stddef.h>}}
\DoxyCodeLine{00023\ }
\DoxyCodeLine{00024\ \textcolor{keyword}{namespace\ }\mbox{\hyperlink{a00935}{AAX}}}
\DoxyCodeLine{00025\ \{}
\DoxyCodeLine{00026\ }
\DoxyCodeLine{00027\ \ \ \ \ \textcolor{keyword}{inline}\ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{a00935_aa7d7e69902012a6272de3ea9aa0264a9}{alignFree}}(\textcolor{keywordtype}{void}\ *p)}
\DoxyCodeLine{00028\ \ \ \ \ \{\ \ \ }
\DoxyCodeLine{00029\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{char}**\ aTempPtr=\textcolor{keyword}{reinterpret\_cast<}\textcolor{keywordtype}{char}**\textcolor{keyword}{>}(p);}
\DoxyCodeLine{00030\ \ \ \ \ \ \ \ \ aTempPtr-\/-\/;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//backup\ 4\ bytes\ past\ the\ beginning\ of\ the\ buffer}}
\DoxyCodeLine{00031\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{char}*\ aRealPtr\ =\ aTempPtr[0];\ \ \ \ \ \ \ \textcolor{comment}{//Get\ the\ real\ address}}
\DoxyCodeLine{00032\ }
\DoxyCodeLine{00033\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(aRealPtr)}
\DoxyCodeLine{00034\ \ \ \ \ \ \ \ \ \ \ \ \ ::delete[]\ aRealPtr;}
\DoxyCodeLine{00035\ \ \ \ \ \}}
\DoxyCodeLine{00036\ }
\DoxyCodeLine{00037\ \ \ \ \ \textcolor{keyword}{template}\ <\textcolor{keyword}{class}\ T>\ }
\DoxyCodeLine{00038\ \ \ \ \ T*\ \mbox{\hyperlink{a00935_ad046542ece5cd75b4971402352ef0ac1}{alignMalloc}}(\textcolor{keywordtype}{int}\ iArraySize,\ \textcolor{keywordtype}{int}\ iAlignment)}
\DoxyCodeLine{00039\ \ \ \ \ \{}
\DoxyCodeLine{00040\ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ We\ can\ seriously\ mess\ ourselves\ up\ if\ alignment\ is\ not\ a\ power\ of\ 2}}
\DoxyCodeLine{00041\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((iAlignment\ !=\ 2)\ \&\&\ (iAlignment\ !=\ 4)\ \&\&\ (iAlignment\ !=\ 8)\ \&\&\ (iAlignment\ !=\ 16)\ \&\&\ (iAlignment\ !=\ 32))\ \{}
\DoxyCodeLine{00042\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00043\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00044\ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ We\ can't\ allocate\ a\ negative-\/size\ array}}
\DoxyCodeLine{00045\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (iArraySize\ <=\ 0)\ \{}
\DoxyCodeLine{00046\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00047\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00048\ }
\DoxyCodeLine{00049\ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{int}\ cSizeOfPointer\ =\ \textcolor{keyword}{sizeof}(\textcolor{keywordtype}{char}*);}
\DoxyCodeLine{00050\ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ Over-\/allocate\ memory\ by\ the\ maximum\ offset\ we\ could\ be\ from\ our\ requested\ alignment}}
\DoxyCodeLine{00051\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{char}*\ aRealPtr\ =\ ::new\ \textcolor{keywordtype}{char}[iArraySize*\textcolor{keyword}{sizeof}(T)\ +\ iAlignment\ +\ cSizeOfPointer];}
\DoxyCodeLine{00052\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (!aRealPtr)\ \{}
\DoxyCodeLine{00053\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00054\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00055\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{char}*\ p=aRealPtr;}
\DoxyCodeLine{00056\ \ \ \ \ \ \ \ \ p+=cSizeOfPointer;\ \ \textcolor{comment}{//Skip\ four\ bytes\ (we\ store\ the\ real\ base\ address\ here)}}
\DoxyCodeLine{00057\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{size\_t}\ mod\ =\ size\_t(p)\ \&\ (iAlignment-\/1);}
\DoxyCodeLine{00058\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (mod)}
\DoxyCodeLine{00059\ \ \ \ \ \ \ \ \ \ \ \ \ p\ +=\ (iAlignment\ -\/\ mod);}
\DoxyCodeLine{00060\ \ \ \ \ \ \ \ \ *\textcolor{keyword}{reinterpret\_cast<}\textcolor{keywordtype}{char}**\textcolor{keyword}{>}(p-\/cSizeOfPointer)=aRealPtr;\ \ \ \textcolor{comment}{//Save\ the\ real\ address.\ \ We'll\ need\ it\ for\ delete.}}
\DoxyCodeLine{00061\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ (T*)\ p;}
\DoxyCodeLine{00062\ \ \ \ \ \}}
\DoxyCodeLine{00063\ \}\ \textcolor{comment}{//\ namespace\ AAX}}
\DoxyCodeLine{00064\ }
\DoxyCodeLine{00065\ \textcolor{preprocessor}{\#endif\ }\textcolor{comment}{//AAX\_ALIGNMENT\_H}}

\end{DoxyCode}
