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