aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2024-01-16 12:11:09 +0100
committerThomas White <taw@physics.org>2024-02-06 16:59:35 +0100
commite92d7d9a24f96549f5fb832efcb9e0f832d28beb (patch)
tree4822e2a928ad6867e4d9d01e2f7fd6b58e27f7b8
parent57ed401c57e8a7548cb21d16495495446e070e13 (diff)
Julia: Use jl_malloc etc for memory management
-rw-r--r--julia/CrystFEL/src/CrystFEL.jl13
1 files changed, 13 insertions, 0 deletions
diff --git a/julia/CrystFEL/src/CrystFEL.jl b/julia/CrystFEL/src/CrystFEL.jl
index dbe31eae..27ee8b0b 100644
--- a/julia/CrystFEL/src/CrystFEL.jl
+++ b/julia/CrystFEL/src/CrystFEL.jl
@@ -13,6 +13,19 @@ module CrystFEL
libcrystfel = "libcrystfel.so"
+# Configure libcrystfel to use Julia's memory management. This is needed so
+# that the Julia GC knows about the memory we allocate via libcrystfel
+# routines. Otherwise, potentially very large objects will be kept hanging
+# around in memory because Julia thinks it's using a very small amount of
+# memory, and rarely runs the GC. In the case of image structures, the
+# difference between apparent and true memory use can be a factor of a million!
+function __init__()
+ @ccall libcrystfel.set_mm_funcs(cglobal(:jl_malloc)::Ptr{Cvoid},
+ cglobal(:jl_free)::Ptr{Cvoid},
+ cglobal(:jl_calloc)::Ptr{Cvoid},
+ cglobal(:jl_realloc)::Ptr{Cvoid})::Cint
+end
+
include("cell.jl")
using .UnitCells
export UnitCell, LatticeType, CenteringType, UniqueAxis