malloc-info.cpp 991 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <library/cpp/malloc/api/malloc.h>
  2. #include <string.h>
  3. using namespace NMalloc;
  4. extern "C" void DisableBalloc();
  5. extern "C" void EnableBalloc();
  6. extern "C" bool BallocDisabled();
  7. namespace {
  8. bool SetAllocParam(const char* name, const char* value) {
  9. if (strcmp(name, "disable") == 0) {
  10. if (value == nullptr || strcmp(value, "false") != 0) {
  11. // all values other than "false" are considred to be "true" for compatibility
  12. DisableBalloc();
  13. } else {
  14. EnableBalloc();
  15. }
  16. return true;
  17. }
  18. return false;
  19. }
  20. bool CheckAllocParam(const char* name, bool defaultValue) {
  21. if (strcmp(name, "disable") == 0) {
  22. return BallocDisabled();
  23. }
  24. return defaultValue;
  25. }
  26. }
  27. TMallocInfo NMalloc::MallocInfo() {
  28. TMallocInfo r;
  29. r.Name = "balloc";
  30. r.SetParam = SetAllocParam;
  31. r.CheckParam = CheckAllocParam;
  32. return r;
  33. }