NVIDIA Iray: Math API
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 1986, 2014 NVIDIA Corporation. All rights reserved.
3
//*****************************************************************************
9
//*****************************************************************************
10
11
#ifndef MI_BASE_DEFAULT_ALLOCATOR_H
12
#define MI_BASE_DEFAULT_ALLOCATOR_H
13
14
#include <
mi/base/types.h
>
15
#include <
mi/base/iallocator.h
>
16
#include <
mi/base/interface_implement.h
>
17
#include <new>
18
19
namespace
mi
20
{
21
22
namespace
base
23
{
24
39
class
Default_allocator
:
public
Interface_implement_singleton
<IAllocator>
40
{
41
Default_allocator
() {}
42
Default_allocator
(
const
Default_allocator
&) {}
43
public
:
44
53
virtual
void
*
malloc
(
Size
size) {
54
// Use non-throwing new call, which may return NULL instead
55
return ::new(std::nothrow)
char
[size];
56
}
57
66
virtual
void
free
(
void
* memory) {
67
::delete[]
reinterpret_cast<
char
*
>
(memory);
68
}
69
71
static
IAllocator
*
get_instance
() {
72
// We claim that this is multithreading safe because the
73
// Default_allocator has an empty default constructor.
74
// Whatever number of threads gets into the constructor, there
75
// should be no way to screw up the initialization in each
76
// thread. The optimizer might even be able to eliminate all
77
// code here.
78
static
Default_allocator
allocator;
79
return
&allocator;
80
}
81
};
82
// end group mi_base_iallocator
84
85
}
// namespace base
86
}
// namespace mi
87
88
#endif // MI_BASE_DEFAULT_ALLOCATOR_H
mi
base
default_allocator.h
Generated on Tue Aug 12 2014 15:28:27. Build 221133.3991, Doxygen 1.8.4