Permalink
Browse files

Added array docs

  • Loading branch information...
1 parent 835636e commit 5cf3908e57ba079d832e431b39513128bb658bb9 @rinon rinon committed Jul 26, 2012
Showing with 33 additions and 0 deletions.
  1. +33 −0 docs/index.html
View
@@ -199,6 +199,39 @@
trace("x = " + x + ", y = " + y);</pre>
+<h4>Arrays</h4>
+
+<p>
+ Typed arrays can be allocated on both the heap and the stack. Stack
+ allocated arrays must, as in C, be fixed length. Heap allocated
+ arrays use a similar syntax to C++ dynamic arrays and their size may
+ be computed at runtime.
+</p>
+
+<pre class="example">
+
+// Stack allocated, fixed size
+let int arr[100];
+arr[5] = 42;
+trace(arr[5]);
+
+// Heap allocated, dynamic size
+for (let int i=1; i <= 10; i++) {
+ let int *heapArr = new int[i];
+ arr[i-1] = i;
+ trace(i + ": " + arr[i-1]);
+}
+
+// Stack allocated array inside a struct
+struct ArrayStruct {
+ int arr[10];
+};
+
+let ArrayStruct s;
+s.arr[0] = 42;
+trace(s.arr[0]);
+</pre>
+
<h2>Objects and Memory</h2>
<p>

0 comments on commit 5cf3908

Please sign in to comment.