bytecode_ptr: add make_zeroed_bytecode_ptr

Rather than always zeroing memory.
This commit is contained in:
Justin Viiret
2017-04-04 11:02:33 +10:00
committed by Matthew Barr
parent 5653fa55a1
commit 63fe84c3f1
19 changed files with 40 additions and 24 deletions

View File

@@ -63,7 +63,6 @@ public:
if (!ptr) {
throw std::bad_alloc();
}
std::memset(ptr.get(), 0, bytes);
}
bytecode_ptr(std::nullptr_t) {}
@@ -122,12 +121,27 @@ private:
size_t alignment = 0; //!< Alignment of memory region in bytes.
};
/**
* \brief Constructs a bytecode_ptr<T> with the given size and alignment.
*/
template<typename T>
inline bytecode_ptr<T> make_bytecode_ptr(size_t size,
size_t align = alignof(T)) {
return bytecode_ptr<T>(size, align);
}
/**
* \brief Constructs a bytecode_ptr<T> with the given size and alignment and
* fills the memory region with zeroes.
*/
template<typename T>
inline bytecode_ptr<T> make_zeroed_bytecode_ptr(size_t size,
size_t align = alignof(T)) {
auto ptr = make_bytecode_ptr<T>(size, align);
std::memset(ptr.get(), 0, size);
return ptr;
}
} // namespace ue2
#endif // UTIL_BYTECODE_PTR_H