aboutsummaryrefslogtreecommitdiff
path: root/c/pl.cpp
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-07-19 12:36:08 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-07-19 12:36:08 +0200
commit61f7d770dbeb5df98b94d9e8cef0c4c86e396447 (patch)
treee0a3d42d578252a7d6b8d3a3e7ced4c75c15c8a2 /c/pl.cpp
parent34c32802122ff80e79d850d44cbc84624d9a5840 (diff)
downloadEpisodeBrowser-61f7d770dbeb5df98b94d9e8cef0c4c86e396447.tar.gz
Use Prolog string buffer marks.
Speaking of unclear documentation, it is not obvious whether it is necessary for programs calling into Prolog to manually mark and release strings. I suppose that it should be, if the same logic that applies to terms apply to strings. On the other hand, the stack in which the strings are stored belongs to Prolog, and there is nothing that would prevent Prolog from cleaning up the strings when called at a later time. I am not sure. But better safe than sorry, I guess. The Mark class acts like the Frame class. The constructor and destructor are equivalent to the PL_STRINGS_MARK and PL_STRINGS_RELEASE macros. Unlike for 34c3280, I did not notice any differences in memory usage after this change. Perhaps that is because it has no effect; perhaps it is because Prolog's stack is very big.
Diffstat (limited to 'c/pl.cpp')
-rw-r--r--c/pl.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/c/pl.cpp b/c/pl.cpp
index a40865f..fb3d4af 100644
--- a/c/pl.cpp
+++ b/c/pl.cpp
@@ -28,6 +28,16 @@ void Frame::Rewind()
PL_rewind_foreign_frame(m_f);
}
+Mark::Mark()
+{
+ PL_mark_string_buffers(&m_m);
+}
+
+Mark::~Mark()
+{
+ PL_release_string_buffers_from_mark(m_m);
+}
+
Query::Query(const module_t ctx, const predicate_t p, const term_t t0)
{
m_q = PL_open_query(ctx, PL_Q_CATCH_EXCEPTION, p, t0);