mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-09-30 11:44:28 +03:00
bytecode_ptr: add make_zeroed_bytecode_ptr
Rather than always zeroing memory.
This commit is contained in:
committed by
Matthew Barr
parent
5653fa55a1
commit
63fe84c3f1
@@ -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
|
||||
|
Reference in New Issue
Block a user