--- Erick Gallesio <eg_at_unice.fr> wrote:
> Genady Veytsman writes:
> >
> > Hello,
> >
> > I can't figure out how to use C-pointers in Stk.
> > Could anybody help me?
> >
> > Here is an example:
> >
> > Let's say there is C function "printhello" in
> library
> > "libhello" and it returns pointer wich was
> declared in
> > C as:
> >
> > double* pSignal;
> >
> > In STk script I write:
> >
> > (define-external phello()
> > :return-type :dynamic-ptr
> > :entry-name "printhello"
> > :library-name "libhello"
> > )
> >
> > (define p (phello))
> >
> > Now "p" contains all the data I need, but
> > how do I access array's elements?
> >
> > Thanks in advance
>
> The main idea behind C pointers in Scheme is that
> you can pass them to
> functions but you cannot dereference them. This is
> useful when you
> have function such as fopen which returns a pointer
> to an object
> that you must pass back to all to functions such as
> fread, fprintf,
> fscanf, ... In this case you don't need to
> dereference the pointer
> returned by fopen. Permitting dereferencing pointers
> is far more
> complicate, since most of the time it is a pointer
> to a structure, and
> in this case we'll need a way to express how to
> access (dynamically) a
> C structure. If the pointer is on a structure,
> you'll have to write a
> C function which allows te access the fields of the
> structure.
> In your case, this is not a structure but a
> predefined type,
> and perhaps I should provide a builtin way to do
> that, but this is not
> the case yet. So, you'lll have to write a conversion
> function C which
> takes a C ppointer and return a Scheme float.
>
> -- Erick
Its not a problem to write such a function but its a
very bad solution. It will slow down the program
significantly. Consider that for every float in the
vector (which can contain thousands of points) you
will need to call the conversion function.
IMHO its absolute must to have some convinient way to
convert pointers (vectors) of predefined types to
scheme vectors.
Thank you for answering
Genady Veytsman
__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/
Received on Tue Apr 24 2001 - 21:27:35 CEST