NVIDIA Iray API
 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>
17 #include <new>
18 
19 namespace mi
20 {
21 
22 namespace base
23 {
24 
40 {
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 
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