New Issue: Expose _ddata or another form of low level, locale aware memory buffer

16797, “dlongnecke-cray”, “Expose _ddata or another form of low level, locale aware memory buffer”, “2020-12-01T05:05:00Z”

Our current strategy for standard library containers requires three essential pieces which we do not expose to users today:

Depending on how discussion in plays out, it may be possible for users to comfortably use arrays as backing store for their own container implementations.

However, I still think it would be useful to expose a lightweight, locale aware buffer to users who wish to build collections without using heavyweight arrays and domains.

Such a buffer would:

  • Not default initialize elements
  • Not be aware of which elements are initialized and which are not
  • Not deinitialize elements upon deinit
  • Store its own size

Additionally, such a buffer could:

  • Provide convenience methods to move-initialize / deinit an element
  • Provide convenience methods to move-initialize / deinit a range of elements
  • Provide optional bounds checking

We could store this buffer in a module called LowLevelBuffer, or store it in LowLevelMove (and perhaps rename that module to something like LowLevelTools).

import LowLevelBuffer;

class C { var x = 0; }

// E.g. allocate a new low level buffer with size 8
const hi = 8;
var buf = new LowLevelBuffer.buffer(shared C, hi);

// Prints '8'

// NO WARNING, ticket to segfault city!

// Go ahead and initialize buffer elements...
for i in 0..<hi do buf.moveInitialize(i, new shared C(i));

// Now a writeln makes sense...

// Simulate a collection operation, deinit the last 4 elements...

// When 'buf' goes out of scope, the first 4 elements won't be deinitialized.
// We have to do it ourselves...