diff --git a/manual/tracy.md b/manual/tracy.md index aeb2334f..19267b5f 100644 --- a/manual/tracy.md +++ b/manual/tracy.md @@ -11,7 +11,7 @@ The user manual **Bartosz Taudul** [\](mailto:wolf@nereid.pl) -2026-08-14 +2026-08-15 # Quick overview {#quick-overview .unnumbered} @@ -1511,10 +1511,13 @@ Tracy can monitor the memory usage of your application. Knowledge about each per - Memory allocation hot-spot tree. -To mark memory events, use the `TracyAlloc(ptr, size)` and `TracyFree(ptr)` macros. Typically you would do that in overloads of `operator new` and `operator delete`, for example: +To mark memory events, use the `TracyAlloc(ptr, size)` and `TracyFree(ptr)` macros. Typically, you would place them in overloads of `operator new` and `operator delete`. The order in which memory events actually occur must match the order reported to the profiler, so a mutex or similar synchronization primitive is required to make the whole operation atomic. Here is an example implementation: + + std::mutex memoryLock; void* operator new(std::size_t count) { + std::lock_guard lock(memoryLock); auto ptr = malloc(count); TracyAlloc(ptr, count); return ptr; @@ -1522,6 +1525,7 @@ To mark memory events, use the `TracyAlloc(ptr, size)` and `TracyFree(ptr)` macr void operator delete(void* ptr) noexcept { + std::lock_guard lock(memoryLock); TracyFree(ptr); free(ptr); }