File indexing completed on 2024-12-01 13:46:11

0001 /*
0002     SPDX-FileCopyrightText: 2016-2017 Milian Wolff <mail@milianw.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-or-later
0005 */
0006 
0007 #ifndef ALLOCATIONDATA_H
0008 #define ALLOCATIONDATA_H
0009 
0010 #include <cstdint>
0011 
0012 struct AllocationData
0013 {
0014     // number of allocations
0015     int64_t allocations = 0;
0016     // number of temporary allocations
0017     int64_t temporary = 0;
0018     // amount of bytes leaked
0019     int64_t leaked = 0;
0020     // largest amount of bytes allocated
0021     int64_t peak = 0;
0022 
0023     void clearCost()
0024     {
0025         *this = {};
0026     }
0027 };
0028 
0029 inline bool operator==(const AllocationData& lhs, const AllocationData& rhs)
0030 {
0031     return lhs.allocations == rhs.allocations && lhs.temporary == rhs.temporary && lhs.leaked == rhs.leaked
0032         && lhs.peak == rhs.peak;
0033 }
0034 
0035 inline bool operator!=(const AllocationData& lhs, const AllocationData& rhs)
0036 {
0037     return !(lhs == rhs);
0038 }
0039 
0040 inline AllocationData& operator+=(AllocationData& lhs, const AllocationData& rhs)
0041 {
0042     lhs.allocations += rhs.allocations;
0043     lhs.temporary += rhs.temporary;
0044     lhs.peak += rhs.peak;
0045     lhs.leaked += rhs.leaked;
0046     return lhs;
0047 }
0048 
0049 inline AllocationData& operator-=(AllocationData& lhs, const AllocationData& rhs)
0050 {
0051     lhs.allocations -= rhs.allocations;
0052     lhs.temporary -= rhs.temporary;
0053     lhs.peak -= rhs.peak;
0054     lhs.leaked -= rhs.leaked;
0055     return lhs;
0056 }
0057 
0058 inline AllocationData operator+(AllocationData lhs, const AllocationData& rhs)
0059 {
0060     return lhs += rhs;
0061 }
0062 
0063 inline AllocationData operator-(AllocationData lhs, const AllocationData& rhs)
0064 {
0065     return lhs -= rhs;
0066 }
0067 
0068 #endif // ALLOCATIONDATA_H