aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/balloc/malloc-info.cpp
blob: de48ae41cea20a92e7f578c3016d9ecfc53c15d7 (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
36
37
38
39
40
41
#include <library/cpp/malloc/api/malloc.h>
 
#include <string.h>
 
using namespace NMalloc; 
 
extern "C" void DisableBalloc();
extern "C" void EnableBalloc();
extern "C" bool BallocDisabled();
 
namespace {
    bool SetAllocParam(const char* name, const char* value) {
        if (strcmp(name, "disable") == 0) {
            if (value == nullptr || strcmp(value, "false") != 0) {
                // all values other than "false" are considred to be "true" for compatibility
                DisableBalloc();
            } else {
                EnableBalloc();
            }
            return true;
        }
        return false;
    }

    bool CheckAllocParam(const char* name, bool defaultValue) {
        if (strcmp(name, "disable") == 0) {
            return BallocDisabled();
        }
        return defaultValue;
    }
}

TMallocInfo NMalloc::MallocInfo() { 
    TMallocInfo r; 

    r.Name = "balloc"; 
    r.SetParam = SetAllocParam;
    r.CheckParam = CheckAllocParam;

    return r; 
}