Skip to content

Commit

Permalink
C++ API remove mgp::memory usage note (#1016)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ignition authored Nov 3, 2024
1 parent 11b1223 commit 74e4e5b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
36 changes: 21 additions & 15 deletions pages/custom-query-modules/cpp/cpp-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 9 additions & 6 deletions pages/custom-query-modules/cpp/cpp-example.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,16 @@ void RandomWalk(mgp_list *args, mgp_graph *memgraph_graph, mgp_result *result, m
<Callout type="error">
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.
</Callout>
Expand Down

0 comments on commit 74e4e5b

Please sign in to comment.