aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/balloc/setup/alloc.h
blob: 89fee3e3e78bb9ccbfacf908370a4b11d2a6a935 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#pragma once

#include <stddef.h>

namespace NAllocSetup {
    void ThrowOnError(size_t allocSize);
    void SetThrowConditions(size_t currSize, size_t maxSize);
    void SetSoftLimit(size_t softLimit);
    void SetHardLimit(size_t hardLimit);
    void SetAllocationThreshold(size_t allocationThreshold);
    void SetSoftReclaimDivisor(size_t softReclaimDivisor);
    void SetAngryReclaimDivisor(size_t angryReclaimDivisor);
    bool CanAlloc(size_t allocSize, size_t totalAllocSize);
    bool NeedReclaim(size_t gcSize_, size_t counter);
    size_t GetTotalAllocSize();
    size_t GetCurSize();
    size_t GetGCSize();

    size_t GetSoftLimit();
    size_t GetHardLimit();
    size_t GetAllocationThreshold();
    size_t GetSoftReclaimDivisor();
    size_t GetAngryReclaimDivisor();

    bool IsEnabledByDefault();

    struct TAllocGuard {
        TAllocGuard(size_t maxSize) {
            SetThrowConditions(0, maxSize);
        }
        ~TAllocGuard() {
            SetThrowConditions(0, 0);
        }
    };
}