How to deal with array pointers in ruby Fiddle

前端 未结 1 1309
执念已碎
执念已碎 2021-01-22 11:36

I am trying to switch from Ruby FFI to Fiddle, which is now part of Ruby std lib.

It is pretty undocumented though, and I am having a hard time in figuring out how to de

相关标签:
1条回答
  • 2021-01-22 12:40

    you mean build an c array and this array`s pointer in ruby?

    you can try like this:

    free = Fiddle::Function.new(Fiddle::RUBY_FREE, [TYPE_VOIDP], TYPE_VOID)
    p = Pointer.malloc(SIZEOF_DOUBLE*len, free)
    

    and call like this:

    my_func(p,len)
    

    ruby GC will call the free function when this memory block will not be used.

    0 讨论(0)
提交回复
热议问题