diff options
| author | Mike Pall <mike> | 2022-06-23 09:10:09 +0200 |
|---|---|---|
| committer | Mike Pall <mike> | 2022-06-23 09:10:09 +0200 |
| commit | 2e98c3d0644fc0c265844908f43b7e4526dd819c (patch) | |
| tree | b9116c671f4268be7776696abdb189de4be5cf43 /doc/ext_ffi.html | |
| parent | 7dc3850e78493eed1e85fa7bc0b96068ae7fb9f4 (diff) | |
| download | luajit-2e98c3d0644fc0c265844908f43b7e4526dd819c.tar.gz luajit-2e98c3d0644fc0c265844908f43b7e4526dd819c.tar.bz2 luajit-2e98c3d0644fc0c265844908f43b7e4526dd819c.zip | |
Grammar and spell check.
Diffstat (limited to 'doc/ext_ffi.html')
| -rw-r--r-- | doc/ext_ffi.html | 14 |
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> |
| 155 | The FFI library allows you to create and access C data | 155 | The FFI library allows you to create and access C data |
| 156 | structures. Of course the main use for this is for interfacing with | 156 | structures. Of course, the main use for this is for interfacing with |
| 157 | C functions. But they can be used stand-alone, too. | 157 | C 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 | |||
| 165 | both a substantial memory overhead as well as a performance overhead. | 165 | both a substantial memory overhead as well as a performance overhead. |
| 166 | </p> | 166 | </p> |
| 167 | <p> | 167 | <p> |
| 168 | Here's a sketch of a library that operates on color images plus a | 168 | Here's a sketch of a library that operates on color images, plus a |
| 169 | simple benchmark. First, the plain Lua version: | 169 | simple 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 |
| 181 | end | 181 | end |
| 182 | 182 | ||
| 183 | local function image_to_grey(img, n) | 183 | local 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 | |||
| 190 | local N = 400*400 | 190 | local N = 400*400 |
| 191 | local img = image_ramp_green(N) | 191 | local img = image_ramp_green(N) |
| 192 | for i=1,1000 do | 192 | for i=1,1000 do |
| 193 | image_to_grey(img, N) | 193 | image_to_gray(img, N) |
| 194 | end | 194 | end |
| 195 | </pre> | 195 | </pre> |
| 196 | <p> | 196 | <p> |
| 197 | This creates a table with 160.000 pixels, each of which is a table | 197 | This creates a table with 160.000 pixels, each of which is a table |
| 198 | holding four number values in the range of 0-255. First an image with | 198 | holding four number values in the range of 0-255. First, an image with |
| 199 | a green ramp is created (1D for simplicity), then the image is | 199 | a green ramp is created (1D for simplicity), then the image is |
| 200 | converted to greyscale 1000 times. Yes, that's silly, but I was in | 200 | converted to grayscale 1000 times. Yes, that's silly, but I was in |
| 201 | need of a simple example ... | 201 | need 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;"> |
| 307 | However the resulting code would be less idiomatic and rather | 307 | However, the resulting code would be less idiomatic and rather |
| 308 | error-prone. And it still doesn't get even close to the performance of | 308 | error-prone. And it still doesn't get even close to the performance of |
| 309 | the FFI version of the code. Also, high-level data structures cannot | 309 | the FFI version of the code. Also, high-level data structures cannot |
| 310 | be easily passed to other C functions, especially I/O functions, | 310 | be easily passed to other C functions, especially I/O functions, |
