OSVR-Core
AlignedMemoryUniquePtr.h
Go to the documentation of this file.
1 
11 // Copyright 2015 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 #ifndef INCLUDED_AlignedMemoryUniquePtr_h_GUID_E68E5347_3A15_4289_4D16_1C9E7B1BCF45
26 #define INCLUDED_AlignedMemoryUniquePtr_h_GUID_E68E5347_3A15_4289_4D16_1C9E7B1BCF45
27 
28 // Internal Includes
30 #include <osvr/Util/UniquePtr.h>
32 
33 // Library/third-party includes
34 // - none
35 
36 // Standard includes
37 // - none
38 
39 namespace osvr {
40 namespace util {
41  using AlignedPtr = unique_ptr<void, AlignedAllocDeleter>;
42  using AlignedImageBufferPtr =
43  unique_ptr<OSVR_ImageBufferElement, AlignedAllocDeleter>;
44 
45  inline AlignedPtr
46  makeAlignedBuffer(size_t bytes,
47  size_t alignment = OSVR_DEFAULT_ALIGN_SIZE) {
48  AlignedPtr ret(util::alignedAlloc(bytes, alignment));
49  return ret;
50  }
51  inline AlignedImageBufferPtr
52  makeAlignedImageBuffer(size_t bytes,
53  size_t alignment = OSVR_DEFAULT_ALIGN_SIZE) {
54  AlignedImageBufferPtr ret(reinterpret_cast<OSVR_ImageBufferElement *>(
55  util::alignedAlloc(bytes, alignment)));
56  return ret;
57  }
58 } // namespace util
59 } // namespace osvr
60 
61 #endif // INCLUDED_AlignedMemoryUniquePtr_h_GUID_E68E5347_3A15_4289_4D16_1C9E7B1BCF45
Definition: RunLoopManager.h:42
The default (and core-utilized) alignment of imaging buffers, etc.
Definition: AlignedMemoryC.h:47
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
Header to bring unique_ptr into the osvr namespace.
Header defining an aligned memory allocator.
void * alignedAlloc(size_t bytes, size_t alignment=OSVR_DEFAULT_ALIGN_SIZE)
Aligned allocation function, gives a pointer to a block of memory aligned to a memory boundary...
Definition: AlignedMemory.h:45