コード例 #1
0
ファイル: test-buffer.js プロジェクト: alivecaobin/node
assert.throws(function() {
  var len = 0xfffff;
  var sbuf = new SlowBuffer(len);
  var buf = new Buffer(sbuf, len, 0);
  SlowBuffer.makeFastBuffer(sbuf, buf, -len, len);  // Should throw.
  for (var i = 0; i < len; ++i) buf[i] = 0x42;      // Try to force segfault.
}, RangeError);
コード例 #2
0
ファイル: fast_buffer2.js プロジェクト: 2hanson/node
function FastBuffer (length) {
  this.length = length;

  if (length > POOLSIZE) {
    // Big buffer, just alloc one.
    this.parent = new Buffer(length);
    this.offset = 0;
  } else {
    // Small buffer.
    if (!pool || pool.length - pool.used < length) allocPool();
    this.parent = pool;
    this.offset = pool.used;
    pool.used += length;
  }

  // HERE HERE HERE
  SlowBuffer.makeFastBuffer(this.parent, this, this.offset, this.length);
}