aboutsummaryrefslogtreecommitdiffhomepage
path: root/libslang/modules/varray.sl
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2011-10-14 04:55:05 +0200
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2011-10-14 04:55:05 +0200
commit6aa0e0017d7d0cddc006da885946934b06949a91 (patch)
tree66b688ec32e2f91266db760b1762f2a50cc52036 /libslang/modules/varray.sl
parenta966db5b71328f6adf9dd767e64b322a3bd7ed9c (diff)
downloaderlang-slang-fork-6aa0e0017d7d0cddc006da885946934b06949a91.tar.gz
include libslang-1.4.9 and automatically build it and link erlang-slang against it
few (erlang) people will still have libslang-1.4.9 installed or spend time to get it to link against the driver
Diffstat (limited to 'libslang/modules/varray.sl')
-rw-r--r--libslang/modules/varray.sl37
1 files changed, 37 insertions, 0 deletions
diff --git a/libslang/modules/varray.sl b/libslang/modules/varray.sl
new file mode 100644
index 0000000..8b78558
--- /dev/null
+++ b/libslang/modules/varray.sl
@@ -0,0 +1,37 @@
+% This file shows how to use the varray-module to treat a file as an
+% array of objects.
+import ("varray");
+
+% First of all, create an array of doubles
+static variable x = [1:1000.0:1.0];
+
+% and write it to disk
+static variable file = "varray_example.dat";
+static variable fp = fopen (file, "wb");
+if (fp == NULL)
+{
+ () = fprintf (stderr, "failed to open %s\n", file);
+ exit (1);
+}
+if ((-1 == fwrite (x, fp))
+ or (-1 == fclose (fp)))
+{
+ () = fprintf (stderr, "Failed to write x\n");
+ exit (1);
+}
+
+% Now associate an array with the file
+variable y = mmap_array (file, 0, _typeof(x), length(x));
+
+if (length (where (y != x)))
+{
+ fprintf (stderr, "mmap_array has failed\n");
+ exit (1);
+}
+
+y = 0; % remove the map
+
+exit (0);
+
+
+