\hypertarget{a00860_source}{}\doxysection{AAX\+\_\+\+Alignment.\+h}
\label{a00860_source}\index{AAX\_Alignment.h@{AAX\_Alignment.h}}
\mbox{\hyperlink{a00860}{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-\/2024\ Avid\ Technology,\ Inc.}}
\DoxyCodeLine{00004\ \textcolor{comment}{\ *\ \ All\ rights\ reserved.}}
\DoxyCodeLine{00005\ \textcolor{comment}{\ *\ \ }}
\DoxyCodeLine{00006\ \textcolor{comment}{\ *\ \ This\ file\ is\ part\ of\ the\ Avid\ AAX\ SDK.}}
\DoxyCodeLine{00007\ \textcolor{comment}{\ *\ \ }}
\DoxyCodeLine{00008\ \textcolor{comment}{\ *\ \ The\ AAX\ SDK\ is\ subject\ to\ commercial\ or\ open-\/source\ licensing.}}
\DoxyCodeLine{00009\ \textcolor{comment}{\ *\ \ }}
\DoxyCodeLine{00010\ \textcolor{comment}{\ *\ \ By\ using\ the\ AAX\ SDK,\ you\ agree\ to\ the\ terms\ of\ both\ the\ Avid\ AAX\ SDK\ License}}
\DoxyCodeLine{00011\ \textcolor{comment}{\ *\ \ Agreement\ and\ Avid\ Privacy\ Policy.}}
\DoxyCodeLine{00012\ \textcolor{comment}{\ *\ \ }}
\DoxyCodeLine{00013\ \textcolor{comment}{\ *\ \ AAX\ SDK\ License:\ https://developer.avid.com/aax}}
\DoxyCodeLine{00014\ \textcolor{comment}{\ *\ \ Privacy\ Policy:\ https://www.avid.com/legal/privacy-\/policy-\/statement}}
\DoxyCodeLine{00015\ \textcolor{comment}{\ *\ \ }}
\DoxyCodeLine{00016\ \textcolor{comment}{\ *\ \ Or:\ You\ may\ also\ use\ this\ code\ under\ the\ terms\ of\ the\ GPL\ v3\ (see}}
\DoxyCodeLine{00017\ \textcolor{comment}{\ *\ \ www.gnu.org/licenses).}}
\DoxyCodeLine{00018\ \textcolor{comment}{\ *\ \ }}
\DoxyCodeLine{00019\ \textcolor{comment}{\ *\ \ THE\ AAX\ SDK\ IS\ PROVIDED\ "{}AS\ IS"{}\ WITHOUT\ ANY\ WARRANTY,\ AND\ ALL\ WARRANTIES,\ WHETHER}}
\DoxyCodeLine{00020\ \textcolor{comment}{\ *\ \ EXPRESSED\ OR\ IMPLIED,\ INCLUDING\ MERCHANTABILITY\ AND\ FITNESS\ FOR\ PURPOSE,\ ARE}}
\DoxyCodeLine{00021\ \textcolor{comment}{\ *\ \ DISCLAIMED.}}
\DoxyCodeLine{00022\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00023\ }
\DoxyCodeLine{00030\ \textcolor{comment}{/*================================================================================================*/}}
\DoxyCodeLine{00031\ }
\DoxyCodeLine{00032\ \textcolor{preprocessor}{\#ifndef\ AAX\_ALIGNMENT\_H}}
\DoxyCodeLine{00033\ \textcolor{preprocessor}{\#define\ AAX\_ALIGNMENT\_H}}
\DoxyCodeLine{00034\ }
\DoxyCodeLine{00035\ \textcolor{preprocessor}{\#include\ <stddef.h>}}
\DoxyCodeLine{00036\ }
\DoxyCodeLine{00037\ \textcolor{keyword}{namespace\ }\mbox{\hyperlink{a00948}{AAX}}}
\DoxyCodeLine{00038\ \{}
\DoxyCodeLine{00039\ }
\DoxyCodeLine{00040\ \ \ \ \ \textcolor{keyword}{inline}\ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{a00948_aa7d7e69902012a6272de3ea9aa0264a9}{alignFree}}(\textcolor{keywordtype}{void}\ *p)}
\DoxyCodeLine{00041\ \ \ \ \ \{\ \ \ }
\DoxyCodeLine{00042\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{char}**\ aTempPtr=\textcolor{keyword}{reinterpret\_cast<}\textcolor{keywordtype}{char}**\textcolor{keyword}{>}(p);}
\DoxyCodeLine{00043\ \ \ \ \ \ \ \ \ aTempPtr-\/-\/;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//backup\ 4\ bytes\ past\ the\ beginning\ of\ the\ buffer}}
\DoxyCodeLine{00044\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{char}*\ aRealPtr\ =\ aTempPtr[0];\ \ \ \ \ \ \ \textcolor{comment}{//Get\ the\ real\ address}}
\DoxyCodeLine{00045\ }
\DoxyCodeLine{00046\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}(aRealPtr)}
\DoxyCodeLine{00047\ \ \ \ \ \ \ \ \ \ \ \ \ ::delete[]\ aRealPtr;}
\DoxyCodeLine{00048\ \ \ \ \ \}}
\DoxyCodeLine{00049\ }
\DoxyCodeLine{00050\ \ \ \ \ \textcolor{keyword}{template}\ <\textcolor{keyword}{class}\ T>\ }
\DoxyCodeLine{00051\ \ \ \ \ T*\ \mbox{\hyperlink{a00948_ad046542ece5cd75b4971402352ef0ac1}{alignMalloc}}(\textcolor{keywordtype}{int}\ iArraySize,\ \textcolor{keywordtype}{int}\ iAlignment)}
\DoxyCodeLine{00052\ \ \ \ \ \{}
\DoxyCodeLine{00053\ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ We\ can\ seriously\ mess\ ourselves\ up\ if\ alignment\ is\ not\ a\ power\ of\ 2}}
\DoxyCodeLine{00054\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ ((iAlignment\ !=\ 2)\ \&\&\ (iAlignment\ !=\ 4)\ \&\&\ (iAlignment\ !=\ 8)\ \&\&\ (iAlignment\ !=\ 16)\ \&\&\ (iAlignment\ !=\ 32))\ \{}
\DoxyCodeLine{00055\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00056\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00057\ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ We\ can't\ allocate\ a\ negative-\/size\ array}}
\DoxyCodeLine{00058\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (iArraySize\ <=\ 0)\ \{}
\DoxyCodeLine{00059\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00060\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00061\ }
\DoxyCodeLine{00062\ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{int}\ cSizeOfPointer\ =\ \textcolor{keyword}{sizeof}(\textcolor{keywordtype}{char}*);}
\DoxyCodeLine{00063\ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ Over-\/allocate\ memory\ by\ the\ maximum\ offset\ we\ could\ be\ from\ our\ requested\ alignment}}
\DoxyCodeLine{00064\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{char}*\ aRealPtr\ =\ ::new\ \textcolor{keywordtype}{char}[iArraySize*\textcolor{keyword}{sizeof}(T)\ +\ iAlignment\ +\ cSizeOfPointer];}
\DoxyCodeLine{00065\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (!aRealPtr)\ \{}
\DoxyCodeLine{00066\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00067\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00068\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{char}*\ p=aRealPtr;}
\DoxyCodeLine{00069\ \ \ \ \ \ \ \ \ p+=cSizeOfPointer;\ \ \textcolor{comment}{//Skip\ four\ bytes\ (we\ store\ the\ real\ base\ address\ here)}}
\DoxyCodeLine{00070\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{size\_t}\ mod\ =\ size\_t(p)\ \&\ (iAlignment-\/1);}
\DoxyCodeLine{00071\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (mod)}
\DoxyCodeLine{00072\ \ \ \ \ \ \ \ \ \ \ \ \ p\ +=\ (iAlignment\ -\/\ mod);}
\DoxyCodeLine{00073\ \ \ \ \ \ \ \ \ *\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{00074\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ (T*)\ p;}
\DoxyCodeLine{00075\ \ \ \ \ \}}
\DoxyCodeLine{00076\ \}\ \textcolor{comment}{//\ namespace\ AAX}}
\DoxyCodeLine{00077\ }
\DoxyCodeLine{00078\ \textcolor{preprocessor}{\#endif\ }\textcolor{comment}{//AAX\_ALIGNMENT\_H}}

\end{DoxyCode}
