From 74e4e5bd3b3a626eaed550a5cb8b31a714ec59fb Mon Sep 17 00:00:00 2001 From: Gareth Andrew Lloyd Date: Sun, 3 Nov 2024 01:18:02 +0000 Subject: [PATCH] C++ API remove mgp::memory usage note (#1016) --- pages/custom-query-modules/cpp/cpp-api.md | 36 +++++++++++-------- .../custom-query-modules/cpp/cpp-example.mdx | 15 ++++---- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/pages/custom-query-modules/cpp/cpp-api.md b/pages/custom-query-modules/cpp/cpp-api.md index 37bcb12c8..4700d923c 100644 --- a/pages/custom-query-modules/cpp/cpp-api.md +++ b/pages/custom-query-modules/cpp/cpp-api.md @@ -6,30 +6,36 @@ description: Get your hands on the API documentation for mgp.hpp, covering decla # Query modules C++ API This is the API documentation for `mgp.hpp`, which contains declarations of all -functions in the C++ API for implementing query module procedures and functions. -The source file can be found in the Memgraph installation directory, under -`/usr/include/memgraph`. +functions in the C++ API for implementing query module procedures and +functions. The source file can be found in the Memgraph installation directory, +under `/usr/include/memgraph`. -To see how to implement query modules in C++, take a look at -[the example we provided](/custom-query-modules/python/python-example). +To see how to implement query modules in C++, take a look at [the example we +provided](/custom-query-modules/python/python-example). If you install any C++ modules after running Memgraph, you’ll need to [load -them into Memgraph](/custom-query-modules/manage-query-modules#loading-query-modules) or restart -Memgraph in order to use them. +them into +Memgraph](/custom-query-modules/manage-query-modules#loading-query-modules) or +restart Memgraph in order to use them. ## Functions and procedures -With this API it’s possible to extend your Cypher queries with **functions** and **procedures** with -`AddProcedure` and `AddFunction`. +With this API it’s possible to extend your Cypher queries with **functions** +and **procedures** with `AddProcedure` and `AddFunction`. -The API needs memory access to add procedures and functions, this can be done with either `mgp::MemoryDispatcherGuard guard(memory);` or `mgp::memory = memory;`, where the use of the former is advised since `mgp::memory = memory;` is not thread-safe and will be deprecated in the future. +The API needs memory access to add procedures and functions, this can be done +with `mgp::MemoryDispatcherGuard guard(memory);`. Old code used `mgp::memory = +memory;`, but this is not thread-safe and has been deprecated. v2.18.1 onwards +you should modify your C++ modules and recompile. v2.21 onwards setting +`mgp::memory` will cause a compilation error, so the guard has to be used. -Functions are simple operations that return a single value and can be used in any expression or predicate. - -Procedures are more complex computations that may modify the graph, and their output is available to -later processing steps in your query. A procedure may only be run from `CALL` clauses. -The output is a stream of **records** that is made accessible with a `YIELD` clause. +Functions are simple operations that return a single value and can be used in +any expression or predicate. +Procedures are more complex computations that may modify the graph, and their +output is available to later processing steps in your query. A procedure may +only be run from `CALL` clauses. The output is a stream of **records** that is +made accessible with a `YIELD` clause. ### AddProcedure diff --git a/pages/custom-query-modules/cpp/cpp-example.mdx b/pages/custom-query-modules/cpp/cpp-example.mdx index b55987665..aa29847f6 100644 --- a/pages/custom-query-modules/cpp/cpp-example.mdx +++ b/pages/custom-query-modules/cpp/cpp-example.mdx @@ -392,13 +392,16 @@ void RandomWalk(mgp_list *args, mgp_graph *memgraph_graph, mgp_result *result, m -As `mgp::memory` is a global object, that means all of the procedures and +`mgp::memory` was a global object, that meant all of the procedures and functions in a single shared library will refer to the same `mgp::memory` -object. As a result, calling such callables simultaneously from multiple threads -will lead to incorrect memory usage. This also includes the case when the same -callable is called from different user sessions. This is a constraint when using -`mgp::memory` so the use of the thread-safe `MemoryDispatcherGuard guard(memory)` -is advised instead. +object. As a result, calling such callables simultaneously from multiple +threads will lead to incorrect memory usage. This also includes the case when +the same callable is called from different user sessions. For some versions of +memgraph this was deprecated and the use of the thread-safe +`MemoryDispatcherGuard guard(memory)` is advised instead. Its has now been +removed and C++ modules should be recompiled for v2.18.1+. v2.21 onwards +setting `mgp::memory` will cause a compilation error, so the guard has to be +used.