[Gambas-user] Complex Numbers and Shared Libraries

Cedron Dawg cedron at exede.net
Sun Feb 24 22:13:27 CET 2019


Hello all,

Well, I'd like to ask for some more specific technical advice.

I am writing a wrapper shared library to access the FFTW library from Gambas.  The design of that library requires that an input and output area be provided to a "preparation step", then subsequent calls use these areas, then they need to be freed.  It is also a requirement that these areas don't move in memory.  Therefore, I am having my wrapper allocate the memory and free it, rather than assume that a Gambas garbage collection won't move it.

So far, I am able to get the address back to Gambas as a pointer.

I can read the memory with either Float@ or reading a memory stream.  No problem.  I can write to the memory using a memory stream.  No problem.

First question:  Is there any other method, particularly one that makes the memory access "look native"?  Similar perhaps to how C allows you to use a pointer with array syntax.

Now we come to the crux of my real question.  The return values from a DFT is an array of complex numbers.  In the FFTW library, a complex number is two adjacent floats in memory, the first being the real part and the second being the imaginary part.

I seem to have three options:

1) Deal with two doubles
2) Use the gb.gsl complex
3) Use gb.complex

The first I know I can do.  The other two are mutually incompatible.  Since I am likely to want to use the gsl for more stuff, I think I would like to use #2.

I've been doing some experimenting and researching, and have not been able to figure out how to get the address of the actual values.  Nor have I been able to read or write complex values to the remote memory area.

Second question:  Is this possible?

I am proceeding under the assumption it is not.  Any opinions on how I am doing things are welcome.  I am still a newbie to Gambas.

Thanks, 
Ced

Yes, I am heavy into Digital Signal Processing, see my stuff at:

dsprelated.com/blogs-1/nf/Cedron_Dawg.php
dsp.stackexchange.com/users/33154/cedron-dawg


More information about the User mailing list