Main Page Class List Class Members

- Main Page
- User's Guide
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

# sdk/extensions/authoring/source/VHACD/inc/btAlignedAllocator.h

Go to the documentation of this file.

    00001 /*
    00002 Bullet Continuous Collision Detection and Physics Library
    00003 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
    00004
    00005 This software is provided 'as-is', without any express or implied warranty.
    00006 In no event will the authors be held liable for any damages arising from the use of this software.
    00007 Permission is granted to anyone to use this software for any purpose,
    00008 including commercial applications, and to alter it and redistribute it freely,
    00009 subject to the following restrictions:
    00010
    00011 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
    00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
    00013 3. This notice may not be removed or altered from any source distribution.
    00014 */
    00015
    00016 #ifndef BT_ALIGNED_ALLOCATOR
    00017 #define BT_ALIGNED_ALLOCATOR
    00018
    00022
    00023 #include "btScalar.h"
    00024 //#define BT_DEBUG_MEMORY_ALLOCATIONS 1
    00025 #ifdef BT_DEBUG_MEMORY_ALLOCATIONS
    00026
    00027 #define btAlignedAlloc(a, b) \
    00028     btAlignedAllocInternal(a, b, __LINE__, __FILE__)
    00029
    00030 #define btAlignedFree(ptr) \
    00031     btAlignedFreeInternal(ptr, __LINE__, __FILE__)
    00032
    00033 void* btAlignedAllocInternal(size_t size, int32_t alignment, int32_t line, char* filename);
    00034
    00035 void btAlignedFreeInternal(void* ptr, int32_t line, char* filename);
    00036
    00037 #else
    00038 void* btAlignedAllocInternal(size_t size, int32_t alignment);
    00039 void btAlignedFreeInternal(void* ptr);
    00040
    00041 #define btAlignedAlloc(size, alignment) btAlignedAllocInternal(size, alignment)
    00042 #define btAlignedFree(ptr) btAlignedFreeInternal(ptr)
    00043
    00044 #endif
    00045 typedef int32_t size_type;
    00046
    00047 typedef void*(btAlignedAllocFunc)(size_t size, int32_t alignment);
    00048 typedef void(btAlignedFreeFunc)(void* memblock);
    00049 typedef void*(btAllocFunc)(size_t size);
    00050 typedef void(btFreeFunc)(void* memblock);
    00051
    00053 void btAlignedAllocSetCustom(btAllocFunc* allocFunc, btFreeFunc* freeFunc);
    00055 void btAlignedAllocSetCustomAligned(btAlignedAllocFunc* allocFunc, btAlignedFreeFunc* freeFunc);
    00056
    00059 template <typename T, unsigned Alignment>
    00060 class btAlignedAllocator {
    00061
    00062     typedef btAlignedAllocator<T, Alignment> self_type;
    00063
    00064 public:
    00065     //just going down a list:
    00066     btAlignedAllocator() {}
    00067     /*
    00068     btAlignedAllocator( const self_type & ) {}
    00069     */
    00070
    00071     template <typename Other>
    00072     btAlignedAllocator(const btAlignedAllocator<Other, Alignment>&) {}
    00073
    00074     typedef const T* const_pointer;
    00075     typedef const T& const_reference;
    00076     typedef T* pointer;
    00077     typedef T& reference;
    00078     typedef T value_type;
    00079
    00080     pointer address(reference ref) const { return &ref; }
    00081     const_pointer address(const_reference ref) const { return &ref; }
    00082     pointer allocate(size_type n, const_pointer* hint = 0)
    00083     {
    00084         (void)hint;
    00085         return reinterpret_cast<pointer>(btAlignedAlloc(sizeof(value_type) * n, Alignment));
    00086     }
    00087     void construct(pointer ptr, const value_type& value) { new (ptr) value_type(value); }
    00088     void deallocate(pointer ptr)
    00089     {
    00090         btAlignedFree(reinterpret_cast<void*>(ptr));
    00091     }
    00092     void destroy(pointer ptr) { ptr->~value_type(); }
    00093
    00094     template <typename O>
    00095     struct rebind {
    00096         typedef btAlignedAllocator<O, Alignment> other;
    00097     };
    00098     template <typename O>
    00099     self_type& operator=(const btAlignedAllocator<O, Alignment>&) { return *this; }
    00100
    00101     friend bool operator==(const self_type&, const self_type&) { return true; }
    00102 };
    00103
    00104 #endif //BT_ALIGNED_ALLOCATOR

Copyright © 2015-2017 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com