aboutsummaryrefslogtreecommitdiff
path: root/doc/ext_ffi.html
diff options
context:
space:
mode:
Diffstat (limited to 'doc/ext_ffi.html')
-rw-r--r--doc/ext_ffi.html14
1 files changed, 7 insertions, 7 deletions
diff --git a/doc/ext_ffi.html b/doc/ext_ffi.html
index 7a87ca65..04b78d98 100644
--- a/doc/ext_ffi.html
+++ b/doc/ext_ffi.html
@@ -153,7 +153,7 @@ call the binding function. Phew!
153<h2 id="cdata">Motivating Example: Using C Data Structures</h2> 153<h2 id="cdata">Motivating Example: Using C Data Structures</h2>
154<p> 154<p>
155The FFI library allows you to create and access C&nbsp;data 155The FFI library allows you to create and access C&nbsp;data
156structures. Of course the main use for this is for interfacing with 156structures. Of course, the main use for this is for interfacing with
157C&nbsp;functions. But they can be used stand-alone, too. 157C&nbsp;functions. But they can be used stand-alone, too.
158</p> 158</p>
159<p> 159<p>
@@ -165,7 +165,7 @@ implemented with a big table holding lots of tiny tables. This imposes
165both a substantial memory overhead as well as a performance overhead. 165both a substantial memory overhead as well as a performance overhead.
166</p> 166</p>
167<p> 167<p>
168Here's a sketch of a library that operates on color images plus a 168Here's a sketch of a library that operates on color images, plus a
169simple benchmark. First, the plain Lua version: 169simple benchmark. First, the plain Lua version:
170</p> 170</p>
171<pre class="code"> 171<pre class="code">
@@ -180,7 +180,7 @@ local function image_ramp_green(n)
180 return img 180 return img
181end 181end
182 182
183local function image_to_grey(img, n) 183local function image_to_gray(img, n)
184 for i=1,n do 184 for i=1,n do
185 local y = floor(0.3*img[i].red + 0.59*img[i].green + 0.11*img[i].blue) 185 local y = floor(0.3*img[i].red + 0.59*img[i].green + 0.11*img[i].blue)
186 img[i].red = y; img[i].green = y; img[i].blue = y 186 img[i].red = y; img[i].green = y; img[i].blue = y
@@ -190,14 +190,14 @@ end
190local N = 400*400 190local N = 400*400
191local img = image_ramp_green(N) 191local img = image_ramp_green(N)
192for i=1,1000 do 192for i=1,1000 do
193 image_to_grey(img, N) 193 image_to_gray(img, N)
194end 194end
195</pre> 195</pre>
196<p> 196<p>
197This creates a table with 160.000 pixels, each of which is a table 197This creates a table with 160.000 pixels, each of which is a table
198holding four number values in the range of 0-255. First an image with 198holding four number values in the range of 0-255. First, an image with
199a green ramp is created (1D for simplicity), then the image is 199a green ramp is created (1D for simplicity), then the image is
200converted to greyscale 1000 times. Yes, that's silly, but I was in 200converted to grayscale 1000 times. Yes, that's silly, but I was in
201need of a simple example ... 201need of a simple example ...
202</p> 202</p>
203<p> 203<p>
@@ -304,7 +304,7 @@ be more compact and faster. This is certainly true (by a factor of
304~1.7x). Switching to a struct-of-arrays would help, too. 304~1.7x). Switching to a struct-of-arrays would help, too.
305</p> 305</p>
306<p style="font-size: 8pt;"> 306<p style="font-size: 8pt;">
307However the resulting code would be less idiomatic and rather 307However, the resulting code would be less idiomatic and rather
308error-prone. And it still doesn't get even close to the performance of 308error-prone. And it still doesn't get even close to the performance of
309the FFI version of the code. Also, high-level data structures cannot 309the FFI version of the code. Also, high-level data structures cannot
310be easily passed to other C&nbsp;functions, especially I/O functions, 310be easily passed to other C&nbsp;functions, especially I/O functions,