2020-12-24 22:18:37 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/types.h>
|
2023-01-16 14:10:31 +00:00
|
|
|
#include <Common/AllocationTrace.h>
|
2020-12-24 22:18:37 +00:00
|
|
|
|
|
|
|
/// Convenience methods, that use current thread's memory_tracker if it is available.
|
2022-07-07 12:24:36 +00:00
|
|
|
struct CurrentMemoryTracker
|
2020-12-24 22:18:37 +00:00
|
|
|
{
|
2022-07-07 12:24:36 +00:00
|
|
|
/// Call the following functions before calling of corresponding operations with memory allocators.
|
2023-01-16 14:10:31 +00:00
|
|
|
[[nodiscard]] static AllocationTrace alloc(Int64 size);
|
|
|
|
[[nodiscard]] static AllocationTrace allocNoThrow(Int64 size);
|
2022-07-07 12:24:36 +00:00
|
|
|
|
|
|
|
/// This function should be called after memory deallocation.
|
2023-01-16 14:10:31 +00:00
|
|
|
[[nodiscard]] static AllocationTrace free(Int64 size);
|
2022-07-07 12:24:36 +00:00
|
|
|
static void check();
|
|
|
|
|
2023-03-16 20:28:07 +00:00
|
|
|
/// Throws MEMORY_LIMIT_EXCEEDED (if it's allowed to throw exceptions)
|
|
|
|
static void injectFault();
|
|
|
|
|
2022-07-07 12:24:36 +00:00
|
|
|
private:
|
2023-01-16 14:10:31 +00:00
|
|
|
[[nodiscard]] static AllocationTrace allocImpl(Int64 size, bool throw_if_memory_exceeded);
|
2022-07-07 12:24:36 +00:00
|
|
|
};
|