Re: What is the best way to call rdf_assert from C?
Jan Wielemaker <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
On 02/03/2014 08:35 AM, Haitao Zhang wrote: > I would like to assert a fair amount of facts directly into the rdf db from > a C extension. I guess the straightforward way is to construct the > rdf_assert term and then do PL_call. Presumably this will go through dwim, > module processing and other overhead etc per call. I wonder if there is a > better way. Ideally I would get a handle to the C function directly. It is surely not going through DWIM. DWIM is only used by the toplevel. A call from C costs a little because the system must create and destroy a `query context', but it isn't too bad: 3 ?- time(forall(between(1, 1000000, _), !1)). time(forall(between(1, 1000000, _), '$sig_atomic'(true))). % 2,000,004 inferences, 0.270 CPU in 0.271 seconds (100% CPU, 7395748 Lips) true. '$sig_atomic'/1 is a C predicate that quite directly calls back Prolog using the argument goal. In fact it calls call(Goal), so there is an additional layer of meta calling you do not need if you call rdf_assert/4. Possibly you could gain a little by creating a list of RDF terms in C and make a single call to assert all elements from the list, but I doubt it is worth the trouble. Cheers --- Jan > Thanks, > Haitao > -------------- next part -------------- > HTML attachment scrubbed and removed > _______________________________________________ > SWI-Prolog mailing list > [email protected] > https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog >