bug-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C Interface Issue


From: Daniel Diaz
Subject: Re: C Interface Issue
Date: Sun, 16 Dec 2012 14:12:19 +0100

Hi John,

The simplest way to pass pointers across Prolog and C is to store them into a 
global array t[] at index i and pass i as a Prolog integer. Obviously you can 
also directly store the structure in the array (this could avoid a malloc/free 
for the struct, but requires more memory if the array is large). The Prolog 
code receives an integer (which it does not use) and passes it back to another 
C code which recover i and uses t[i].

Did I miss something ?

Daniel


Le 15 déc. 2012 à 22:05, mcculloch <address@hidden> a écrit :

> I've looked into various prologs and have decided Gnu Prolog is the easiest
> to interface to other systems via C routines.  However, there doesn't seem
> to be a good way to pass C struct pointers back to prolog for use by other
> foreign predicate calls implemented in C.  I think now maybe that might not
> be a good idea anyway.
> 
> The C interface I want to use creates a structure to represent a connection
> to a foreign system, and then requires this structure to subsequently access
> the system.  (For those who are curious, the system is mongoDB).  
> 
> One option is to create this structure, use it and destroy it every time a
> predicate is called that uses that system.  Obviously, this is very
> inefficient.  The other option is to provide a predicate that returns the
> connection structure back to prolog to provide to other predicates, but this
> is exactly what I can't figure out how to do in gprolog.
> 
> Any ideas would be greatly appreciated, and of course, any code that I
> develop to completion will be shared.
> 
> John
> 
> 
> Sorry this ended up in Bugs where it doesn't belong.  I'll try and figure
> out how to move it.
> 
> 
> -- 
> View this message in context: 
> http://old.nabble.com/C-Interface-Issue-tp34801402p34801402.html
> Sent from the Gnu - Prolog - Bugs mailing list archive at Nabble.com.
> 
> 
> _______________________________________________
> Bug-prolog mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/bug-prolog
> 
> -- 
> Ce message a ete verifie par MailScanner
> pour des virus ou des polluriels et rien de
> suspect n'a ete trouve.
> 


-- 
Ce message a ete verifie par MailScanner
pour des virus ou des polluriels et rien de
suspect n'a ete trouve.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]