GRPC Core
9.0.0
src
core
lib
gprpp
memory.h
Go to the documentation of this file.
1
/*
2
*
3
* Copyright 2017 gRPC authors.
4
*
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at
8
*
9
* http://www.apache.org/licenses/LICENSE-2.0
10
*
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
16
*
17
*/
18
19
#ifndef GRPC_CORE_LIB_GPRPP_MEMORY_H
20
#define GRPC_CORE_LIB_GPRPP_MEMORY_H
21
22
#include <
grpc/support/port_platform.h
>
23
24
#include <
grpc/support/alloc.h
>
25
#include <
grpc/support/log.h
>
26
27
#include <limits>
28
#include <memory>
29
#include <utility>
30
31
namespace
grpc_core
{
32
33
class
DefaultDeleteChar
{
34
public
:
35
void
operator()
(
char
* p) {
36
if
(p ==
nullptr
)
return
;
37
gpr_free
(p);
38
}
39
};
40
41
// UniquePtr<T> is only allowed for char and UniquePtr<char> is deprecated
42
// in favor of std::string. UniquePtr<char> is equivalent std::unique_ptr
43
// except that it uses gpr_free for deleter.
44
template
<
typename
T>
45
using
UniquePtr
= std::unique_ptr<T, DefaultDeleteChar>;
46
47
// TODO(veblush): Replace this with absl::make_unique once abseil is added.
48
template
<
typename
T,
typename
... Args>
49
inline
std::unique_ptr<T>
MakeUnique
(Args&&... args) {
50
return
std::unique_ptr<T>(
new
T(std::forward<Args>(args)...));
51
}
52
53
}
// namespace grpc_core
54
55
#endif
/* GRPC_CORE_LIB_GPRPP_MEMORY_H */
grpc_core
Round Robin Policy.
Definition:
backend_metric.cc:24
gpr_free
GPRAPI void gpr_free(void *ptr)
free
Definition:
alloc.cc:50
grpc_core::DefaultDeleteChar
Definition:
memory.h:33
grpc_core::MakeUnique
std::unique_ptr< T > MakeUnique(Args &&... args)
Definition:
memory.h:49
grpc_core::DefaultDeleteChar::operator()
void operator()(char *p)
Definition:
memory.h:35
log.h
grpc_core::UniquePtr
std::unique_ptr< T, DefaultDeleteChar > UniquePtr
Definition:
memory.h:45
alloc.h
port_platform.h
Generated on Wed Sep 13 2023 00:00:00 for GRPC Core by
1.8.20