summaryrefslogtreecommitdiffhomepage
path: root/neat.html.markdown
diff options
context:
space:
mode:
authorFeepingCreature <default_357-line@yahoo.de>2013-09-08 13:40:48 +0200
committerFeepingCreature <default_357-line@yahoo.de>2013-09-08 13:40:48 +0200
commitf5f3f2b3e5a6e3579d8f2217c96b5cd0d96298ee (patch)
tree705d1bf9b3e3f4088815c9a9f5a2b7484bd48e85 /neat.html.markdown
parentff24568b098b2233961408960ab30518acaebe32 (diff)
Document appender arrays and scope guards
Diffstat (limited to 'neat.html.markdown')
-rw-r--r--neat.html.markdown24
1 files changed, 24 insertions, 0 deletions
diff --git a/neat.html.markdown b/neat.html.markdown
index b7777cdc..6a319a7d 100644
--- a/neat.html.markdown
+++ b/neat.html.markdown
@@ -141,6 +141,30 @@ void main(string[] args) {
assert !(hewo is s);
// same as
assert (hewo !is s);
+
+ // Allocate arrays using "new array length"
+ int[] integers = new int[] 10;
+ assert(integers.length == 10);
+ assert(integers[0] == 0); // zero is default initializer
+ integers = integers ~ 5; // This allocates a new array!
+ assert(integers.length == 11);
+
+ // This is an appender array.
+ // Instead of (length, pointer), it tracks (capacity, length, pointer).
+ // When you append to it, it will use the free capacity if it can.
+ // If it runs out of space, it reallocates - but it will free the old array automatically.
+ // This makes it convenient for building arrays.
+ int[auto~] appender;
+ appender ~= 2;
+ appender ~= 3;
+ appender.free(); // same as {mem.free(appender.ptr); appender = null;}
+
+ // Scope variables are automatically freed at the end of the current scope.
+ scope int[auto~] someOtherAppender;
+ // This is the same as:
+ int[auto~] someOtherAppender2;
+ onExit { someOtherAppender2.free; }
+
// You can do a C for loop too
// - but why would you want to?
for (int i = 0; i < 5; ++i) { }