Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Create new Buffer(length) zeroed #472

wants to merge 2 commits into from

3 participants

xk commented

Currently a new Buffer() contains garbage:

new Buffer(5) -> Buffer 0f 82 1e 03 00, with this patch : new Buffer(5) -> Buffer 00 00 00 00 00

ry commented

I don't want the overhead. won't apply.


I think this is a valid feature. Maybe we can expose the memset function in another way. So that you can call it from JS without necessarily running it for each Buffer allocation

@ssuda ssuda referenced this pull request from a commit in ssuda/node
@isaacs isaacs Upgrade npm to 1.1.6
* Fix #472 Adds support for os/cpu fields in package.json (Adam Blackburn)
* Don't use existing pkg if explicit
* Install missing deps, even if they are in bundleDependencies
* bundle node-gyp
* Automatically node-gyp build stuff with a bindings.gyp
* Fix #2230 Unpack in place. No folder renaming malarky
* Never create un-listable directories
* Fix cases where an optionalDependency fails to build
* Always ignore .wafpickle-7 files
* fix shrinkwrap test
* Fix: bundleDependencies being re-installed unnecessarily
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 29, 2010
  1. @xk

    create new Buffers zeroed

    xk committed
  2. @xk

    use memset

    xk committed
This page is out of date. Refresh to see the latest.
Showing with 5 additions and 1 deletion.
  1. +5 −1 src/
6 src/
@@ -188,8 +188,12 @@ void Buffer::Replace(char *data, size_t length,
data_ = data;
} else if (length_) {
data_ = new char[length_];
- if (data)
+ if (data) {
memcpy(data_, data, length_);
+ }
+ else {
+ memset( (void*)(data_), 0, length_);
+ }
V8::AdjustAmountOfExternalAllocatedMemory(sizeof(Buffer) + length_);
} else {
data_ = NULL;
Something went wrong with that request. Please try again.