From d7d4c2699059edec65bec32fe491e31051e7419d Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Fri, 7 Sep 2018 01:51:38 +0200 Subject: [PATCH] Add example of overloading operator new and delete. --- manual/tracy.tex | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/manual/tracy.tex b/manual/tracy.tex index 59cfc678..7e0be842 100644 --- a/manual/tracy.tex +++ b/manual/tracy.tex @@ -422,7 +422,22 @@ Tracy can monitor memory usage of your application. Knowledge about each perform \item Memory allocation hot-spot tree. \end{itemize} -To mark memory events, use the \texttt{TracyAlloc(ptr, size)} and \texttt{TracyFree(ptr)} macros. Typically you would do that in overloads of \texttt{operator new} and \texttt{operator delete}. +To mark memory events, use the \texttt{TracyAlloc(ptr, size)} and \texttt{TracyFree(ptr)} macros. Typically you would do that in overloads of \texttt{operator new} and \texttt{operator delete}, for example: + +\begin{lstlisting} +void* operator new( std::size_t count ) +{ + auto ptr = malloc( count ); + TracyAlloc( ptr, count ); + return ptr; +} + +void operator delete( void* ptr ) noexcept +{ + TracyFree( ptr ); + free( ptr ); +} +\end{lstlisting} \subsection{Lua support}