Std.buffer.scopebuffer

From D Wiki
Revision as of 14:21, 17 February 2014 by Dicebot (talk | contribs) (Created page with "== Description == [https://github.com/D-Programming-Language/phobos/pull/1911 std.buffer.scopebuffer] is a module authored by Walter Bright. <blockquote>ScopeBuffer is an Ou...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Description

std.buffer.scopebuffer is a module authored by Walter Bright.

ScopeBuffer is an OutputRange that sits on the stack, and overflows to

malloc/free. It's designed to help in eliminating gc allocation by lower level functions that return buffers, such as std.path.buildPath(). With some judicious user tuning of the initial stack size, it can virtually eliminate storage

allocation.

Related links

Initial announcement / discussion

Current state

After preliminary discussion proposal is about to enter formal review process.

Initial discussion

concerns raised and answered

   Q: Why can't ScopeBuffer contain initial static array itself?
   A: 1) performance (fitting 2 registers -> faster passing to functions)
      2) avoid default-init of array
      3) more flexible (any memory block can be used)
      4) avoiding internal reference
   Q: How does it fit std.allocator?
   A: Current std.allocator shape is not clear enough to rely on it, ScopeBuffer is stand-alone
   Q: Why not use alloca to create buffer internally?
   A: alloca() cannot be used to allocate stack data in a function enclosing the current one

Various small implementation comments/issues have been adressed within linked pull request.

remaining concerns

  • Missing pre-generated documentation
  • Lack of documentation coverage
  • Some style differences from majority of "modern" Phobos
  • Relation with postblit-enabled types