OSVR-Core
AlignedMemory.h
Go to the documentation of this file.
1 
11 /*
12 // Copyright 2015 Sensics, Inc.
13 //
14 // Licensed under the Apache License, Version 2.0 (the "License");
15 // you may not use this file except in compliance with the License.
16 // You may obtain a copy of the License at
17 //
18 // http://www.apache.org/licenses/LICENSE-2.0
19 //
20 // Unless required by applicable law or agreed to in writing, software
21 // distributed under the License is distributed on an "AS IS" BASIS,
22 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 // See the License for the specific language governing permissions and
24 // limitations under the License.
25 */
26 
27 #ifndef INCLUDED_AlignedMemory_h_GUID_552DA92F_420A_4ADB_BCD2_493486A1C7A1
28 #define INCLUDED_AlignedMemory_h_GUID_552DA92F_420A_4ADB_BCD2_493486A1C7A1
29 
30 // Internal Includes
32 
33 // Library/third-party includes
34 // - none
35 
36 // Standard includes
37 #include <stdlib.h>
38 #include <stdexcept>
39 
40 namespace osvr {
41 namespace util {
42 
45  inline void *alignedAlloc(size_t bytes,
46  size_t alignment = OSVR_DEFAULT_ALIGN_SIZE) {
47  void *ret = osvrAlignedAlloc(bytes, alignment);
48  if (!ret) {
49  throw std::runtime_error("Could not perform aligned allocation!");
50  }
51  return ret;
52  }
53 
56  inline void alignedFree(void *p) { osvrAlignedFree(p); }
57 
60  public:
61  void operator()(void *p) const { alignedFree(p); }
62  };
63 } // namespace util
64 } // namespace osvr
65 #endif // INCLUDED_AlignedMemory_h_GUID_552DA92F_420A_4ADB_BCD2_493486A1C7A1
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
Deleter class matching alignedAlloc.
Definition: AlignedMemory.h:59
OSVR_UTIL_EXPORT void osvrAlignedFree(void *p)
Aligned deallocation function, uses the pointer to the original memory block to deallocate it...
Definition: AlignedMemoryC.cpp:64
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
void alignedFree(void *p)
Aligned deallocation function, uses the pointer to the original memory block to deallocate it...
Definition: AlignedMemory.h:56
OSVR_UTIL_EXPORT void * osvrAlignedAlloc(size_t bytes, size_t alignment OSVR_CPP_ONLY(=OSVR_DEFAULT_ALIGN_SIZE))
Aligned allocation function, gives a pointer to a block of memory aligned to a memory boundary...