Why does rgeo have CAPI and FFI factories to achieve the same goal?

118 Views Asked by At

If I understand the Rgeo doc & code correctly, there's CAPIFactory which is supposed to link to GEOS and there is FFIFactory using ffi-geos gem which links to GEOS using FFI.

Both of these seem to be achieving the same objective. Why does Rgeo implement 2 separate factories for the same thing?

1

There are 1 best solutions below

0
Keith Doggett On

The CAPIFactory can be used for versions of Ruby that support C Extensions. The most common version of Ruby (MRI) is written in C and thus supports C Extensions, but other kinds (JRuby for example) are written in Java or other languages that don't support C Extensions. In that case, they can use the FFIFactory to interface with GEOS, but it is not as fast as the native CAPIFactory.

Basically, the FFIFactory gives the ability to use GEOS to all versions of Ruby at the cost of some performance.