From: sh@... Date: 2009-05-05T23:06:09+09:00 Subject: [ruby-core:23359] Re: Ruby/DL Documentation Hi, It is helpful to read test/dl/test_*.rb in ruby-1.9.tar.gz. You have to master pack and unpack anyway. The following is an example. $ cat sum.c double sum(double *arry, int len) { double ret = 0; int i; for(i = 0; i < len; i++){ ret = ret + arry[i]; } return ret; } $ gcc -shared sum.c -o libsum.so $ cat d.rb require 'dl/import' module M extend DL::Importer dlload './libsum.so' extern 'double sum(double*, int)' end p M.sum([2.0, 3.0, 4.0].pack("d*"), 3) $ ruby-1.9 -v d.rb ruby 1.9.2dev (2009-05-02 trunk 23326) [i686-linux] 9.0 2009/5/4 Aston : > Hello, > > recently i have been trying to learn and use dl library. while searching i > found this excellent link > http://www.jbrowse.com/text/rdl_en.html > > unfortunately it is specific to 1.8.x > > i wonder how people here use DL, since it is very scarcely documented. i > have been trying to > hack around ./ext/dl/*.c files but i have gained very little usable > information. > > ok, my question is about passing an array from ruby to some native libraries > (IPP(http://software.intel.com/en-us/intel-ipp/) to be specific) > on windows. yes i about other alternatives, i could embed ruby in my app and > do whatever, there is gr8 support there > but this is about quickly loading and using native libraries via dynamic > loader. > > consider code below > some_fast_math_function( float* array, int len); > > then how to pass 'array' argument from ruby ? > i tried this > > require 'dl' > > module NativeLibs > # do the job for accessing some_fast_math_function > end > > array = DL.malloc(size) > NativeLibs.some_fast_math_function( array, size) # crashes :( > > some how sucess is elusive for me, this crashes(core dumps) for me, i am > sure this is due to my inexperienced stunts with DL > > Aston > > > ________________________________ > Now surf faster and smarter ! Check out the new Firefox 3 - Yahoo! Edition * > Click here!