diff options
| author | Bryan Galdrikian <[email protected]> | 2017-02-24 09:32:20 -0800 |
|---|---|---|
| committer | Bryan Galdrikian <[email protected]> | 2017-02-24 09:32:20 -0800 |
| commit | e1bf674c16e3c8472b29574159c789cd3f0c64e0 (patch) | |
| tree | 9f0cfce09c71a2c27ff19589fcad6cd83504477c /sdk/common/NvBlastFixedBoolArray.h | |
| parent | first commit (diff) | |
| download | blast-e1bf674c16e3c8472b29574159c789cd3f0c64e0.tar.xz blast-e1bf674c16e3c8472b29574159c789cd3f0c64e0.zip | |
Updating to [email protected] and [email protected] with a new directory structure.
NvBlast folder is gone, files have been moved to top level directory. README is changed to reflect this.
Diffstat (limited to 'sdk/common/NvBlastFixedBoolArray.h')
| -rw-r--r-- | sdk/common/NvBlastFixedBoolArray.h | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/sdk/common/NvBlastFixedBoolArray.h b/sdk/common/NvBlastFixedBoolArray.h new file mode 100644 index 0000000..253bed6 --- /dev/null +++ b/sdk/common/NvBlastFixedBoolArray.h @@ -0,0 +1,106 @@ +/* +* Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved. +* +* NVIDIA CORPORATION and its licensors retain all intellectual property +* and proprietary rights in and to this software, related documentation +* and any modifications thereto. Any use, reproduction, disclosure or +* distribution of this software and related documentation without an express +* license agreement from NVIDIA CORPORATION is strictly prohibited. +*/ + +#ifndef NVBLASTFIXEDBOOLARRAY_H +#define NVBLASTFIXEDBOOLARRAY_H + +#include "NvBlastAssert.h" +#include "NvBlastMemory.h" +#include <cstring> + +namespace Nv +{ +namespace Blast +{ + +/*! +FixedBoolArray is an array of bools of fixed size, it's intended to be used with placement new on chunk of memory. +It'll use following memory for data layout. As follows: + +// some memory +char *buf = new char[64 * 1024]; + +const uint32_t size = 100; + +// placement new on this memory +FixedBoolArray* arr = new (buf) FixedBoolArray(size); + +// you can get max requiredMemorySize by an bitMap to use memory left +buf = buf + FixedBoolArray<SomeClass>::requiredMemorySize(size); + +buf: + ++------------------------------------------------------------+ +| uint32_t | bool0 | bool1 | bool2 | ... | ++------------------------------------------------------------+ + +*/ +class FixedBoolArray +{ +public: + explicit FixedBoolArray(uint32_t size) + { + m_size = size; + } + + static size_t requiredMemorySize(uint32_t size) + { + return align16(sizeof(FixedBoolArray)) + align16(size); + } + + void clear() + { + memset(data(), 0, m_size); + } + + void fill() + { + memset(data(), 1, m_size); + } + + int test(uint32_t index) const + { + NVBLAST_ASSERT(index < m_size); + return data()[index]; + } + + void set(uint32_t index) + { + NVBLAST_ASSERT(index < m_size); + data()[index] = 1; + } + + void reset(uint32_t index) + { + NVBLAST_ASSERT(index < m_size); + data()[index] = 0; + } + +private: + uint32_t m_size; + + NV_FORCE_INLINE char* data() + { + return ((char*)this + sizeof(FixedBoolArray)); + } + + NV_FORCE_INLINE const char* data() const + { + return ((char*)this + sizeof(FixedBoolArray)); + } + +private: + FixedBoolArray(const FixedBoolArray& that); +}; + +} // namespace Blast +} // namespace Nv + +#endif // ifndef NVBLASTFIXEDBOOLARRAY_H |