You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@quickstep.apache.org by zu...@apache.org on 2016/05/30 22:47:30 UTC
[22/32] incubator-quickstep git commit: In ScopedBuffer,
initialize the allocated memory bytes to 0 (#230)
In ScopedBuffer, initialize the allocated memory bytes to 0 (#230)
Project: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/commit/be35bb5b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/tree/be35bb5b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/diff/be35bb5b
Branch: refs/heads/master
Commit: be35bb5b008d974faf6638cf40f446128f38030a
Parents: 0fffe50
Author: Jianqiao Zhu <ji...@cs.wisc.edu>
Authored: Thu May 19 18:20:53 2016 -0500
Committer: Zuyu Zhang <zz...@pivotal.io>
Committed: Mon May 30 15:47:52 2016 -0700
----------------------------------------------------------------------
utility/ScopedBuffer.hpp | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/be35bb5b/utility/ScopedBuffer.hpp
----------------------------------------------------------------------
diff --git a/utility/ScopedBuffer.hpp b/utility/ScopedBuffer.hpp
index b6fddc5..03290ff 100644
--- a/utility/ScopedBuffer.hpp
+++ b/utility/ScopedBuffer.hpp
@@ -43,9 +43,13 @@ class ScopedBuffer {
* size.
*
* @param alloc_size The number of bytes of memory to allocate.
+ * @param initialize If true, initialize all the bytes of the allocated memory to 0.
**/
- explicit ScopedBuffer(const std::size_t alloc_size) {
+ explicit ScopedBuffer(const std::size_t alloc_size, bool initialize = true) {
internal_ptr_ = std::malloc(alloc_size);
+ if (initialize) {
+ memset(internal_ptr_, 0x0, alloc_size);
+ }
}
/**
@@ -54,10 +58,15 @@ class ScopedBuffer {
*
* @param alloc_size The number of bytes of memory to allocate.
* @param alloc_alignment The alignment of the memory to allocate.
+ * @param initialize If true, initialize all the bytes of the allocated memory to 0.
**/
ScopedBuffer(const std::size_t alloc_size,
- const std::size_t alloc_alignment) {
+ const std::size_t alloc_alignment,
+ const bool initialize = true) {
internal_ptr_ = malloc_with_alignment(alloc_size, alloc_alignment);
+ if (initialize) {
+ memset(internal_ptr_, 0x0, alloc_size);
+ }
}
/**
@@ -110,12 +119,16 @@ class ScopedBuffer {
* size.
*
* @param alloc_size The number of bytes of memory to allocate.
+ * @param initialize If true, initialize all the bytes of the allocated memory to 0.
**/
- void reset(const std::size_t alloc_size) {
+ void reset(const std::size_t alloc_size, const bool initialize = true) {
if (internal_ptr_ != nullptr) {
std::free(internal_ptr_);
}
internal_ptr_ = std::malloc(alloc_size);
+ if (initialize) {
+ memset(internal_ptr_, 0x0, alloc_size);
+ }
}
/**