Re: ffi cdef hash table

  • From: Luke Gorrie <luke@xxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 9 Apr 2015 12:40:55 +0200

On 16 March 2015 at 22:31, Mike Pall <mike-1503@xxxxxxxxxx> wrote:

But ... strings as keys is a perfect use case for a plain Lua
table, which is really a hash table under the hood. And the code
has been heavily optimized already.

Simply turn C strings to Lua strings with ffi.string() and then
use them as keys for a Lua table. You can store an ffi array of
doubles as a value (or whatever object you need).


Are there some GC effects that you would have to be careful of in this case?

I would love to do this in some code too. My concern is that ffi.string()
will allocate frequently to intern the strings (many GCs) and that GC will
sweep through the tables (long GCs). I would love to learn that these
concerns are overblown :).

Other related posts: