From 9f96e7b7c87672161737459d10f5b2af04b42773 Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Wed, 15 Sep 2021 12:16:20 -0500 Subject: [PATCH] Add scope definition functions --- src/coffi/ffi.clj | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/coffi/ffi.clj b/src/coffi/ffi.clj index 9eac051..a7541c2 100644 --- a/src/coffi/ffi.clj +++ b/src/coffi/ffi.clj @@ -110,6 +110,22 @@ ([obj type] (serialize obj type (ResourceScope/newImplicitScope))) ([obj type scope] (serialize* obj type (alloc-instance type scope) scope))) +(defn stack-scope + "Constructs a new scope for use only in this thread. + + The memory allocated within this scope is cheap to allocate, like a native + stack." + [] + (ResourceScope/newConfinedScope)) + +(defn shared-scope + "Constructs a new shared scope. + + This scope can be shared across threads and memory allocated in it will only + be cleaned up once every thread accessing the scope closes it." + [] + (ResourceScope/newSharedScope)) + (comment ;;; Prospective syntax for ffi