|
MemViz v1.0.0
C++ Memory Layout Inspector
|
Namespaces | |
| namespace | detail |
Classes | |
| struct | AllocationInfo |
| struct | MemberInfo |
Functions | |
| template<typename To , typename From > | |
| void | castAndPrint (From from) |
| Bitwise casts an object to another type and prints the result. | |
| template<typename T > | |
| constexpr auto | getMembers () |
Retrieves a compile-time tuple of member information for type T. | |
| auto & | table () |
| Access the singleton allocation table. | |
| std::mutex & | lock () |
| Access the global mutex used to protect the table. | |
| void | on_alloc (const void *ptr, std::size_t sz) |
| Register a new allocation. | |
| void | on_free (const void *ptr) |
| Unregister a freed allocation. | |
| bool | isLive (const void *ptr) |
| Check if a pointer is currently tracked as allocated. | |
| void | reportLeaks (std::ostream &os=std::cout) |
| Print a summary of all currently live allocations (potential leaks). | |
| void | printAllocationLog (std::ostream &os=std::cout) |
| Print all currently tracked allocations. | |
| void memviz::castAndPrint | ( | From | from | ) |
Bitwise casts an object to another type and prints the result.
This function uses std::bitcast (C++20) to reinterpret the bits of a value of type From as a value of type To. It then outputs the cast result to std::cout.
| To | The destination type to cast to. Must be trivially copyable and have the same size as From. Must be printable via operator<<. |
| From | The source type to cast from. Must be trivially copyable and have the same size as To. |
| from | The value to be cast. |
To and From must be trivially copyable and of equal size. To does not have an operator<< overload, this function will fail to compile.Retrieves a compile-time tuple of member information for type T.
This function returns the result of memviz::MemberInfo<T>::get(), which should be defined via the MEMVIZ_REGISTER macro. It is used internally by dumpLayout<T>() to inspect object layout at runtime.
| T | The user-defined type being introspected. |
std::tuple of std::pair<const char*, T member_ptr> representing member names and pointers.MemberInfo<T> is not specialized, this function will cause a compile-time error. Use if constexpr (requires { MemberInfo<T>::get(); }) to guard calls safely.Check if a pointer is currently tracked as allocated.
| ptr | Pointer to check. |
|
inline |
Access the global mutex used to protect the table.
Register a new allocation.
| ptr | Pointer to the allocated memory block. |
| size | Size of the allocated block in bytes. |
If ptr is null, this call is ignored. If tracking is already active (e.g., recursive initialization), the call is skipped.
Unregister a freed allocation.
| ptr | Pointer to the memory block being freed. |
If ptr is null, this call is ignored. If tracking is disabled (re-entrancy), the call is skipped.
|
inline |
Print all currently tracked allocations.
| os | Output stream to print to (default = std::cout). |
This is similar to reportLeaks, but reports each tracked block as "LIVE" (no summary of total leaks). Useful for debugging allocation state.
|
inline |
Print a summary of all currently live allocations (potential leaks).
| os | Output stream to print to (default = std::cout). |
Prints each live allocation pointer and its size, followed by a summary line with the total number of leaks and total leaked bytes.
|
inline |
Access the singleton allocation table.
The table maps pointer addresses to allocation information. It is allocated on the heap to avoid static destruction order issues.