YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/util/memory/mc_types.cc
Line
Count
Source (jump to first uncovered line)
1
//--------------------------------------------------------------------------------------------------
2
// Copyright (c) YugaByte, Inc.
3
//
4
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5
// in compliance with the License.  You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software distributed under the License
10
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11
// or implied.  See the License for the specific language governing permissions and limitations
12
// under the License.
13
//
14
//--------------------------------------------------------------------------------------------------
15
16
#include "yb/util/memory/mc_types.h"
17
18
#include "yb/util/memory/arena.h"
19
20
namespace yb {
21
22
//--------------------------------------------------------------------------------------------------
23
24
0
char *MCStrdup(MemoryContext *memctx, const char *str) {
25
0
  if (str == nullptr) {
26
0
    return nullptr;
27
0
  }
28
29
0
  const size_t bytes = strlen(str) + 1;
30
0
  return static_cast<char*>(memcpy(memctx->AllocateBytes(bytes), str, bytes));
31
0
}
32
33
//--------------------------------------------------------------------------------------------------
34
35
9.99M
MCBase::MCBase(MemoryContext *memctx) {
36
9.99M
}
37
38
10.0M
MCBase::~MCBase() {
39
10.0M
}
40
41
// Delete operator is a NO-OP. The custom allocator (e.g. Arena) will free it when the associated
42
// memory context is deleted.
43
99
void MCBase::operator delete(void *ptr) noexcept {
44
99
}
45
46
// Operator new with placement allocate an object of any derived classes of MCBase.
47
198
void *MCBase::operator new(size_t bytes, Arena *arena) noexcept {
48
198
  return arena->AllocateBytesAligned(bytes, sizeof(void*));
49
198
}
50
51
0
void *MCBase::operator new(size_t bytes, void* ptr) noexcept {
52
0
  return ptr;
53
0
}
54
55
}  // namespace yb