MDL SDK API
Up
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
default_allocator.h
Go to the documentation of this file.
1
/***************************************************************************************************
2
* Copyright 2022 NVIDIA Corporation. All rights reserved.
3
**************************************************************************************************/
8
9
#ifndef MI_BASE_DEFAULT_ALLOCATOR_H
10
#define MI_BASE_DEFAULT_ALLOCATOR_H
11
12
#include <
mi/base/types.h
>
13
#include <
mi/base/iallocator.h
>
14
#include <
mi/base/interface_implement.h
>
15
#include <new>
16
17
namespace
mi
18
{
19
20
namespace
base
21
{
22
37
class
Default_allocator
:
public
Interface_implement_singleton
<IAllocator>
38
{
39
Default_allocator
() {}
40
Default_allocator
(
const
Default_allocator
&) {}
41
public
:
42
51
virtual
void
*
malloc
(
Size
size) {
52
// Use non-throwing new call, which may return NULL instead
53
return ::new(std::nothrow)
char
[size];
54
}
55
64
virtual
void
free
(
void
* memory) {
65
::delete[]
reinterpret_cast<
char
*
>
(memory);
66
}
67
69
static
IAllocator
*
get_instance
() {
70
// We claim that this is multithreading safe because the
71
// Default_allocator has an empty default constructor.
72
// Whatever number of threads gets into the constructor, there
73
// should be no way to screw up the initialization in each
74
// thread. The optimizer might even be able to eliminate all
75
// code here.
76
static
Default_allocator
allocator;
77
return
&allocator;
78
}
79
};
80
// end group mi_base_iallocator
82
83
}
// namespace base
84
}
// namespace mi
85
86
#endif // MI_BASE_DEFAULT_ALLOCATOR_H
5 April 2022, 20:40, rev.358266
© 2022 NVIDIA Corporation.
All rights reserved.