aboutsummaryrefslogblamecommitdiffstats
path: root/library/cpp/balloc/malloc-info.cpp
blob: 604b1fb145d54e5ea0dd68b5b4a8751b6a33fd45 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
                                          
 
                   

                        
                                

                                 
           
                                                             
                                           




                                                                                             


                        





                                                               
 
                                   
 
                      
                               
                                   
 
             
#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;
}