Merge branch 'master' into develop

This commit is contained in:
Joshua Suskalo 2021-10-25 09:49:12 -05:00
commit f89f1cdd4c
2 changed files with 30 additions and 30 deletions

View file

@ -2,18 +2,18 @@
"">
<html><head><meta charset="UTF-8" /><title>coffi.ffi documentation</title><link rel="stylesheet" type="text/css" href="css/default.css" /><link rel="stylesheet" type="text/css" href="css/highlight.css" /><script type="text/javascript" src="js/highlight.min.js"></script><script type="text/javascript" src="js/jquery.min.js"></script><script type="text/javascript" src="js/page_effects.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body><div id="header"><h2>Generated by <a href="https://github.com/weavejester/codox">Codox</a></h2><h1><a href="index.html"><span class="project-title"><span class="project-name">coffi</span> <span class="project-version">v0.2.259</span></span></a></h1></div><div class="sidebar primary"><h3 class="no-link"><span class="inner">Project</span></h3><ul class="index-link"><li class="depth-1 "><a href="index.html"><div class="inner">Index</div></a></li></ul><h3 class="no-link"><span class="inner">Namespaces</span></h3><ul><li class="depth-1"><div class="no-link"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>coffi</span></div></div></li><li class="depth-2 branch current"><a href="coffi.ffi.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>ffi</span></div></a></li><li class="depth-2"><a href="coffi.mem.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>mem</span></div></a></li></ul></div><div class="sidebar secondary"><h3><a href="#top"><span class="inner">Public Vars</span></a></h3><ul><li class="depth-1"><a href="coffi.ffi.html#var-cfn"><div class="inner"><span>cfn</span></div></a></li><li class="depth-1"><a href="coffi.ffi.html#var-const"><div class="inner"><span>const</span></div></a></li><li class="depth-1"><a href="coffi.ffi.html#var-defcfn"><div class="inner"><span>defcfn</span></div></a></li><li class="depth-1"><a href="coffi.ffi.html#var-find-symbol"><div class="inner"><span>find-symbol</span></div></a></li><li class="depth-1"><a href="coffi.ffi.html#var-freset.21"><div class="inner"><span>freset!</span></div></a></li><li class="depth-1"><a href="coffi.ffi.html#var-fswap.21"><div class="inner"><span>fswap!</span></div></a></li><li class="depth-1"><a href="coffi.ffi.html#var-load-library"><div class="inner"><span>load-library</span></div></a></li><li class="depth-1"><a href="coffi.ffi.html#var-load-system-library"><div class="inner"><span>load-system-library</span></div></a></li><li class="depth-1"><a href="coffi.ffi.html#var-make-downcall"><div class="inner"><span>make-downcall</span></div></a></li><li class="depth-1"><a href="coffi.ffi.html#var-make-serde-varargs-wrapper"><div class="inner"><span>make-serde-varargs-wrapper</span></div></a></li><li class="depth-1"><a href="coffi.ffi.html#var-make-serde-wrapper"><div class="inner"><span>make-serde-wrapper</span></div></a></li><li class="depth-1"><a href="coffi.ffi.html#var-make-varargs-factory"><div class="inner"><span>make-varargs-factory</span></div></a></li><li class="depth-1"><a href="coffi.ffi.html#var-reify-libspec"><div class="inner"><span>reify-libspec</span></div></a></li><li class="depth-1"><a href="coffi.ffi.html#var-reify-symbolspec"><div class="inner"><span>reify-symbolspec</span></div></a></li><li class="depth-1"><a href="coffi.ffi.html#var-static-variable"><div class="inner"><span>static-variable</span></div></a></li><li class="depth-1"><a href="coffi.ffi.html#var-vacfn-factory"><div class="inner"><span>vacfn-factory</span></div></a></li></ul></div><div class="namespace-docs" id="content"><h1 class="anchor" id="top">coffi.ffi</h1><div class="doc"><div class="markdown"><p>Functions for creating handles to native functions and loading native libraries.</p></div></div><div class="public anchor" id="var-cfn"><h3>cfn</h3><div class="usage"><code>(cfn symbol args ret)</code></div><div class="doc"><div class="markdown"><p>Constructs a Clojure function to call the native function referenced by <code>symbol</code>.</p>
<p>The function returned will serialize any passed arguments into the <code>args</code> types, and deserialize the return to the <code>ret</code> type.</p>
<p>If your <code>args</code> and <code>ret</code> are constants, then it is more efficient to call <a href="coffi.ffi.html#var-make-downcall">make-downcall</a> followed by <a href="coffi.ffi.html#var-make-serde-wrapper">make-serde-wrapper</a> because the latter has an inline definition which will result in less overhead from serdes.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/ffi.clj#L420">view source</a></div></div><div class="public anchor" id="var-const"><h3>const</h3><div class="usage"><code>(const symbol-or-addr type)</code></div><div class="doc"><div class="markdown"><p>Gets the value of a constant stored in <code>symbol-or-addr</code>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/ffi.clj#L555">view source</a></div></div><div class="public anchor" id="var-defcfn"><h3>defcfn</h3><h4 class="type">macro</h4><div class="usage"><code>(defcfn name docstring? attr-map? symbol arg-types ret-type)</code><code>(defcfn name docstring? attr-map? symbol arg-types ret-type native-fn &amp; fn-tail)</code></div><div class="doc"><div class="markdown"><p>Defines a Clojure function which maps to a native function.</p>
<p>If your <code>args</code> and <code>ret</code> are constants, then it is more efficient to call <a href="coffi.ffi.html#var-make-downcall">make-downcall</a> followed by <a href="coffi.ffi.html#var-make-serde-wrapper">make-serde-wrapper</a> because the latter has an inline definition which will result in less overhead from serdes.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/ffi.clj#L420">view source</a></div></div><div class="public anchor" id="var-const"><h3>const</h3><div class="usage"><code>(const symbol-or-addr type)</code></div><div class="doc"><div class="markdown"><p>Gets the value of a constant stored in <code>symbol-or-addr</code>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/ffi.clj#L555">view source</a></div></div><div class="public anchor" id="var-defcfn"><h3>defcfn</h3><h4 class="type">macro</h4><div class="usage"><code>(defcfn name docstring? attr-map? symbol arg-types ret-type)</code><code>(defcfn name docstring? attr-map? symbol arg-types ret-type native-fn &amp; fn-tail)</code></div><div class="doc"><div class="markdown"><p>Defines a Clojure function which maps to a native function.</p>
<p><code>name</code> is the symbol naming the resulting var. <code>symbol</code> is a symbol or string naming the library symbol to link against. <code>arg-types</code> is a vector of qualified keywords representing the argument types. <code>ret-type</code> is a single qualified keyword representing the return type. <code>fn-tail</code> is the body of the function (potentially with multiple arities) which wraps the native one. Inside the function, <code>native-fn</code> is bound to a function that will serialize its arguments, call the native function, and deserialize its return type. If any body is present, you must call this function in order to call the native code.</p>
<p>If no <code>fn-tail</code> is provided, then the resulting function will simply serialize the arguments according to <code>arg-types</code>, call the native function, and deserialize the return value.</p>
<p>The number of args in the <code>fn-tail</code> need not match the number of <code>arg-types</code> for the native function. It need only call the native wrapper function with the correct arguments.</p>
<p>See <a href="coffi.mem.html#var-serialize">serialize</a>, <a href="coffi.mem.html#var-deserialize">deserialize</a>, <a href="coffi.ffi.html#var-make-downcall">make-downcall</a>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/ffi.clj#L691">view source</a></div></div><div class="public anchor" id="var-find-symbol"><h3>find-symbol</h3><div class="usage"><code>(find-symbol sym)</code></div><div class="doc"><div class="markdown"><p>Gets the <a href="null">MemoryAddress</a> of a symbol from the loaded libraries.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/ffi.clj#L35">view source</a></div></div><div class="public anchor" id="var-freset.21"><h3>freset!</h3><div class="usage"><code>(freset! static-var newval)</code></div><div class="doc"><div class="markdown"><p>Sets the value of <code>static-var</code> to <code>newval</code>, running it through <a href="coffi.mem.html#var-serialize">serialize</a>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/ffi.clj#L580">view source</a></div></div><div class="public anchor" id="var-fswap.21"><h3>fswap!</h3><div class="usage"><code>(fswap! static-var f &amp; args)</code></div><div class="doc"><div class="markdown"><p>Non-atomically runs the function <code>f</code> over the value stored in <code>static-var</code>.</p>
<p>The value is deserialized before passing it to <code>f</code>, and serialized before putting the value into <code>static-var</code>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/ffi.clj#L589">view source</a></div></div><div class="public anchor" id="var-load-library"><h3>load-library</h3><div class="usage"><code>(load-library path)</code></div><div class="doc"><div class="markdown"><p>Loads the library at <code>path</code>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/ffi.clj#L30">view source</a></div></div><div class="public anchor" id="var-load-system-library"><h3>load-system-library</h3><div class="usage"><code>(load-system-library libname)</code></div><div class="doc"><div class="markdown"><p>Loads the library named <code>libname</code> from the systems load path.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/ffi.clj#L25">view source</a></div></div><div class="public anchor" id="var-make-downcall"><h3>make-downcall</h3><div class="usage"><code>(make-downcall symbol-or-addr args ret)</code></div><div class="doc"><div class="markdown"><p>Constructs a downcall function reference to <code>symbol-or-addr</code> with the given <code>args</code> and <code>ret</code> types.</p>
<p>See <a href="coffi.mem.html#var-serialize">serialize</a>, <a href="coffi.mem.html#var-deserialize">deserialize</a>, <a href="coffi.ffi.html#var-make-downcall">make-downcall</a>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/ffi.clj#L691">view source</a></div></div><div class="public anchor" id="var-find-symbol"><h3>find-symbol</h3><div class="usage"><code>(find-symbol sym)</code></div><div class="doc"><div class="markdown"><p>Gets the <a href="null">MemoryAddress</a> of a symbol from the loaded libraries.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/ffi.clj#L35">view source</a></div></div><div class="public anchor" id="var-freset.21"><h3>freset!</h3><div class="usage"><code>(freset! static-var newval)</code></div><div class="doc"><div class="markdown"><p>Sets the value of <code>static-var</code> to <code>newval</code>, running it through <a href="coffi.mem.html#var-serialize">serialize</a>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/ffi.clj#L580">view source</a></div></div><div class="public anchor" id="var-fswap.21"><h3>fswap!</h3><div class="usage"><code>(fswap! static-var f &amp; args)</code></div><div class="doc"><div class="markdown"><p>Non-atomically runs the function <code>f</code> over the value stored in <code>static-var</code>.</p>
<p>The value is deserialized before passing it to <code>f</code>, and serialized before putting the value into <code>static-var</code>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/ffi.clj#L589">view source</a></div></div><div class="public anchor" id="var-load-library"><h3>load-library</h3><div class="usage"><code>(load-library path)</code></div><div class="doc"><div class="markdown"><p>Loads the library at <code>path</code>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/ffi.clj#L30">view source</a></div></div><div class="public anchor" id="var-load-system-library"><h3>load-system-library</h3><div class="usage"><code>(load-system-library libname)</code></div><div class="doc"><div class="markdown"><p>Loads the library named <code>libname</code> from the systems load path.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/ffi.clj#L25">view source</a></div></div><div class="public anchor" id="var-make-downcall"><h3>make-downcall</h3><div class="usage"><code>(make-downcall symbol-or-addr args ret)</code></div><div class="doc"><div class="markdown"><p>Constructs a downcall function reference to <code>symbol-or-addr</code> with the given <code>args</code> and <code>ret</code> types.</p>
<p>The function returned takes only arguments whose types match exactly the <a href="coffi.mem.html#var-java-layout">java-layout</a> for that type, and returns an argument with exactly the <a href="coffi.mem.html#var-java-layout">java-layout</a> of the <code>ret</code> type. This function will perform no serialization or deserialization of arguments or the return type.</p>
<p>If the <code>ret</code> type is non-primitive, then the returned function will take a first argument of a <a href="null">SegmentAllocator</a>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/ffi.clj#L196">view source</a></div></div><div class="public anchor" id="var-make-serde-varargs-wrapper"><h3>make-serde-varargs-wrapper</h3><div class="usage"><code>(make-serde-varargs-wrapper varargs-factory required-args ret-type)</code></div><div class="doc"><div class="markdown"><p>Constructs a wrapper function for the <code>varargs-factory</code> which produces functions that serialize the arguments and deserialize the return value.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/ffi.clj#L408">view source</a></div></div><div class="public anchor" id="var-make-serde-wrapper"><h3>make-serde-wrapper</h3><div class="usage"><code>(make-serde-wrapper downcall arg-types ret-type)</code></div><div class="doc"><div class="markdown"><p>Constructs a wrapper function for the <code>downcall</code> which serializes the arguments and deserializes the return value.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/ffi.clj#L389">view source</a></div></div><div class="public anchor" id="var-make-varargs-factory"><h3>make-varargs-factory</h3><div class="usage"><code>(make-varargs-factory symbol required-args ret)</code></div><div class="doc"><div class="markdown"><p>Returns a function for constructing downcalls with additional types for arguments.</p>
<p>If the <code>ret</code> type is non-primitive, then the returned function will take a first argument of a <a href="null">SegmentAllocator</a>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/ffi.clj#L196">view source</a></div></div><div class="public anchor" id="var-make-serde-varargs-wrapper"><h3>make-serde-varargs-wrapper</h3><div class="usage"><code>(make-serde-varargs-wrapper varargs-factory required-args ret-type)</code></div><div class="doc"><div class="markdown"><p>Constructs a wrapper function for the <code>varargs-factory</code> which produces functions that serialize the arguments and deserialize the return value.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/ffi.clj#L408">view source</a></div></div><div class="public anchor" id="var-make-serde-wrapper"><h3>make-serde-wrapper</h3><div class="usage"><code>(make-serde-wrapper downcall arg-types ret-type)</code></div><div class="doc"><div class="markdown"><p>Constructs a wrapper function for the <code>downcall</code> which serializes the arguments and deserializes the return value.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/ffi.clj#L389">view source</a></div></div><div class="public anchor" id="var-make-varargs-factory"><h3>make-varargs-factory</h3><div class="usage"><code>(make-varargs-factory symbol required-args ret)</code></div><div class="doc"><div class="markdown"><p>Returns a function for constructing downcalls with additional types for arguments.</p>
<p>The <code>required-args</code> are the types of the first arguments passed to the downcall handle, and the values passed to the returned function are only the varargs types.</p>
<p>The returned function is memoized, so that only one downcall function will be generated per combination of argument types.</p>
<p>See <a href="coffi.ffi.html#var-make-downcall">make-downcall</a>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/ffi.clj#L214">view source</a></div></div><div class="public anchor" id="var-reify-libspec"><h3>reify-libspec</h3><div class="usage"><code>(reify-libspec libspec)</code></div><div class="doc"><div class="markdown"><p>Loads all the symbols specified in the <code>libspec</code>.</p>
<p>The value of each key of the passed map is transformed as by <a href="coffi.ffi.html#var-reify-symbolspec">reify-symbolspec</a>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/ffi.clj#L653">view source</a></div></div><div class="public anchor" id="var-reify-symbolspec"><h3>reify-symbolspec</h3><h4 class="type">multimethod</h4><div class="usage"></div><div class="doc"><div class="markdown"><p>Takes a spec for a symbol reference and returns a live value for that type.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/ffi.clj#L612">view source</a></div></div><div class="public anchor" id="var-static-variable"><h3>static-variable</h3><div class="usage"><code>(static-variable symbol-or-addr type)</code></div><div class="doc"><div class="markdown"><p>Constructs a reference to a mutable value stored in <code>symbol-or-addr</code>.</p>
<p>See <a href="coffi.ffi.html#var-make-downcall">make-downcall</a>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/ffi.clj#L214">view source</a></div></div><div class="public anchor" id="var-reify-libspec"><h3>reify-libspec</h3><div class="usage"><code>(reify-libspec libspec)</code></div><div class="doc"><div class="markdown"><p>Loads all the symbols specified in the <code>libspec</code>.</p>
<p>The value of each key of the passed map is transformed as by <a href="coffi.ffi.html#var-reify-symbolspec">reify-symbolspec</a>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/ffi.clj#L653">view source</a></div></div><div class="public anchor" id="var-reify-symbolspec"><h3>reify-symbolspec</h3><h4 class="type">multimethod</h4><div class="usage"></div><div class="doc"><div class="markdown"><p>Takes a spec for a symbol reference and returns a live value for that type.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/ffi.clj#L612">view source</a></div></div><div class="public anchor" id="var-static-variable"><h3>static-variable</h3><div class="usage"><code>(static-variable symbol-or-addr type)</code></div><div class="doc"><div class="markdown"><p>Constructs a reference to a mutable value stored in <code>symbol-or-addr</code>.</p>
<p>The returned value can be dereferenced, and has metadata, and the address of the value can be queried with <a href="coffi.mem.html#var-address-of">address-of</a>.</p>
<p>See <a href="coffi.ffi.html#var-freset.21">freset!</a>, <a href="coffi.ffi.html#var-fswap.21">fswap!</a>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/ffi.clj#L597">view source</a></div></div><div class="public anchor" id="var-vacfn-factory"><h3>vacfn-factory</h3><div class="usage"><code>(vacfn-factory symbol required-args ret)</code></div><div class="doc"><div class="markdown"><p>Constructs a varargs factory to call the native function referenced by <code>symbol</code>.</p>
<p>The function returned takes any number of type arguments and returns a specialized Clojure function for calling the native function with those arguments.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/ffi.clj#L434">view source</a></div></div></div></body></html>
<p>See <a href="coffi.ffi.html#var-freset.21">freset!</a>, <a href="coffi.ffi.html#var-fswap.21">fswap!</a>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/ffi.clj#L597">view source</a></div></div><div class="public anchor" id="var-vacfn-factory"><h3>vacfn-factory</h3><div class="usage"><code>(vacfn-factory symbol required-args ret)</code></div><div class="doc"><div class="markdown"><p>Constructs a varargs factory to call the native function referenced by <code>symbol</code>.</p>
<p>The function returned takes any number of type arguments and returns a specialized Clojure function for calling the native function with those arguments.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/ffi.clj#L434">view source</a></div></div></div></body></html>

View file

@ -4,34 +4,34 @@
<p>For any new type to be implemented, three multimethods must be overriden, but which three depends on the native representation of the type.</p>
<p>If the native representation of the type is a primitive (whether or not other data beyond the primitive is associated with it, as e.g. a pointer), then <a href="coffi.mem.html#var-primitive-type">primitive-type</a> must be overriden to return which primitive type it is serialized as, then <a href="coffi.mem.html#var-serialize*">serialize*</a> and <a href="coffi.mem.html#var-deserialize*">deserialize*</a> should be overriden.</p>
<p>If the native representation of the type is a composite type, like a union, struct, or array, then <a href="coffi.mem.html#var-c-layout">c-layout</a> must be overriden to return the native layout of the type, and <a href="coffi.mem.html#var-serialize-into">serialize-into</a> and <a href="coffi.mem.html#var-deserialize-from">deserialize-from</a> should be overriden to allow marshaling values of the type into and out of memory segments.</p>
<p>When writing code that manipulates a segment, its best practice to use <a href="coffi.mem.html#var-with-acquired">with-acquired</a> on the <a href="coffi.mem.html#var-segment-scope">segment-scope</a> in order to ensure it wont be released during its manipulation.</p></div></div><div class="public anchor" id="var-add-close-action.21"><h3>add-close-action!</h3><div class="usage"><code>(add-close-action! scope action)</code></div><div class="doc"><div class="markdown"><p>Adds a 0-arity function to be run when the <code>scope</code> closes.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L182">view source</a></div></div><div class="public anchor" id="var-address-of"><h3>address-of</h3><div class="usage"><code>(address-of addressable)</code></div><div class="doc"><div class="markdown"><p>Gets the address of a given segment.</p>
<p>This value can be used as an argument to functions which take a pointer.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L121">view source</a></div></div><div class="public anchor" id="var-address.3F"><h3>address?</h3><div class="usage"><code>(address? addr)</code></div><div class="doc"><div class="markdown"><p>Checks if an object is a memory address.</p>
<p><code>nil</code> is considered an address.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L133">view source</a></div></div><div class="public anchor" id="var-alloc"><h3>alloc</h3><div class="usage"><code>(alloc size)</code><code>(alloc size scope)</code></div><div class="doc"><div class="markdown"><p>Allocates <code>size</code> bytes.</p>
<p>If a <code>scope</code> is provided, the allocation will be reclaimed when it is closed.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L86">view source</a></div></div><div class="public anchor" id="var-alloc-instance"><h3>alloc-instance</h3><div class="usage"><code>(alloc-instance type)</code><code>(alloc-instance type scope)</code></div><div class="doc"><div class="markdown"><p>Allocates a memory segment for the given <code>type</code>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L352">view source</a></div></div><div class="public anchor" id="var-alloc-with"><h3>alloc-with</h3><div class="usage"><code>(alloc-with allocator size)</code><code>(alloc-with allocator size alignment)</code></div><div class="doc"><div class="markdown"><p>Allocates <code>size</code> bytes using the <code>allocator</code>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L93">view source</a></div></div><div class="public anchor" id="var-as-segment"><h3>as-segment</h3><div class="usage"><code>(as-segment address size scope)</code><code>(as-segment address size scope cleanup)</code></div><div class="doc"><div class="markdown"><p>Dereferences an <code>address</code> into a memory segment associated with the <code>scope</code>.</p>
<p>If <code>cleanup</code> is provided, it is a 0-arity function run when the scope is closed. This can be used to register a free method for the memory, or do other cleanup in a way that doesnt require modifying the code at the point of freeing, and allows shared or garbage collected resources to be freed correctly.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L169">view source</a></div></div><div class="public anchor" id="var-c-layout"><h3>c-layout</h3><h4 class="type">multimethod</h4><div class="usage"></div><div class="doc"><div class="markdown"><p>Gets the layout object for a given <code>type</code>.</p>
<p>When writing code that manipulates a segment, its best practice to use <a href="coffi.mem.html#var-with-acquired">with-acquired</a> on the <a href="coffi.mem.html#var-segment-scope">segment-scope</a> in order to ensure it wont be released during its manipulation.</p></div></div><div class="public anchor" id="var-add-close-action.21"><h3>add-close-action!</h3><div class="usage"><code>(add-close-action! scope action)</code></div><div class="doc"><div class="markdown"><p>Adds a 0-arity function to be run when the <code>scope</code> closes.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L182">view source</a></div></div><div class="public anchor" id="var-address-of"><h3>address-of</h3><div class="usage"><code>(address-of addressable)</code></div><div class="doc"><div class="markdown"><p>Gets the address of a given segment.</p>
<p>This value can be used as an argument to functions which take a pointer.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L121">view source</a></div></div><div class="public anchor" id="var-address.3F"><h3>address?</h3><div class="usage"><code>(address? addr)</code></div><div class="doc"><div class="markdown"><p>Checks if an object is a memory address.</p>
<p><code>nil</code> is considered an address.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L133">view source</a></div></div><div class="public anchor" id="var-alloc"><h3>alloc</h3><div class="usage"><code>(alloc size)</code><code>(alloc size scope)</code></div><div class="doc"><div class="markdown"><p>Allocates <code>size</code> bytes.</p>
<p>If a <code>scope</code> is provided, the allocation will be reclaimed when it is closed.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L86">view source</a></div></div><div class="public anchor" id="var-alloc-instance"><h3>alloc-instance</h3><div class="usage"><code>(alloc-instance type)</code><code>(alloc-instance type scope)</code></div><div class="doc"><div class="markdown"><p>Allocates a memory segment for the given <code>type</code>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L352">view source</a></div></div><div class="public anchor" id="var-alloc-with"><h3>alloc-with</h3><div class="usage"><code>(alloc-with allocator size)</code><code>(alloc-with allocator size alignment)</code></div><div class="doc"><div class="markdown"><p>Allocates <code>size</code> bytes using the <code>allocator</code>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L93">view source</a></div></div><div class="public anchor" id="var-as-segment"><h3>as-segment</h3><div class="usage"><code>(as-segment address size scope)</code><code>(as-segment address size scope cleanup)</code></div><div class="doc"><div class="markdown"><p>Dereferences an <code>address</code> into a memory segment associated with the <code>scope</code>.</p>
<p>If <code>cleanup</code> is provided, it is a 0-arity function run when the scope is closed. This can be used to register a free method for the memory, or do other cleanup in a way that doesnt require modifying the code at the point of freeing, and allows shared or garbage collected resources to be freed correctly.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L169">view source</a></div></div><div class="public anchor" id="var-c-layout"><h3>c-layout</h3><h4 class="type">multimethod</h4><div class="usage"></div><div class="doc"><div class="markdown"><p>Gets the layout object for a given <code>type</code>.</p>
<p>If a type is primitive it will return the appropriate primitive layout (see <a href="null">c-prim-layout</a>).</p>
<p>Otherwise, it should return a <a href="null">GroupLayout</a> for the given type.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L277">view source</a></div></div><div class="public anchor" id="var-clone-segment"><h3>clone-segment</h3><div class="usage"><code>(clone-segment segment)</code><code>(clone-segment segment scope)</code></div><div class="doc"><div class="markdown"><p>Clones the content of <code>segment</code> into a new segment of the same size.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L193">view source</a></div></div><div class="public anchor" id="var-connected-scope"><h3>connected-scope</h3><div class="usage"><code>(connected-scope)</code></div><div class="doc"><div class="markdown"><p>Constructs a new scope to reclaim all connected resources at once.</p>
<p>Otherwise, it should return a <a href="null">GroupLayout</a> for the given type.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L277">view source</a></div></div><div class="public anchor" id="var-clone-segment"><h3>clone-segment</h3><div class="usage"><code>(clone-segment segment)</code><code>(clone-segment segment scope)</code></div><div class="doc"><div class="markdown"><p>Clones the content of <code>segment</code> into a new segment of the same size.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L193">view source</a></div></div><div class="public anchor" id="var-connected-scope"><h3>connected-scope</h3><div class="usage"><code>(connected-scope)</code></div><div class="doc"><div class="markdown"><p>Constructs a new scope to reclaim all connected resources at once.</p>
<p>The scope may be shared across threads, and all resources created with it will be cleaned up at the same time, when all references have been collected.</p>
<p>This type of scope cannot be closed, and therefore should not be created in a <a href="null">with-open</a> clause.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L51">view source</a></div></div><div class="public anchor" id="var-copy-segment"><h3>copy-segment</h3><div class="usage"><code>(copy-segment dest src)</code></div><div class="doc"><div class="markdown"><p>Copies the content to <code>dest</code> from <code>src</code></p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L187">view source</a></div></div><div class="public anchor" id="var-defalias"><h3>defalias</h3><h4 class="type">macro</h4><div class="usage"><code>(defalias new-type aliased-type)</code></div><div class="doc"><div class="markdown"><p>Defines a type alias from <code>new-type</code> to <code>aliased-type</code>.</p>
<p>This creates needed serialization and deserialization implementations for the aliased type.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L772">view source</a></div></div><div class="public anchor" id="var-deserialize"><h3>deserialize</h3><div class="usage"><code>(deserialize obj type)</code></div><div class="doc"><div class="markdown"><p>Deserializes an arbitrary type.</p>
<p>For types which have a primitive representation, this deserializes the primitive representation. For types which do not, this deserializes out of a segment.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L629">view source</a></div></div><div class="public anchor" id="var-deserialize*"><h3>deserialize*</h3><h4 class="type">multimethod</h4><div class="usage"></div><div class="doc"><div class="markdown"><p>Deserializes a primitive object into a Clojure data structure.</p>
<p>This is intended for use with types that are returned as a primitive but which need additional processing before they can be returned.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L569">view source</a></div></div><div class="public anchor" id="var-deserialize-from"><h3>deserialize-from</h3><h4 class="type">multimethod</h4><div class="usage"></div><div class="doc"><div class="markdown"><p>Deserializes the given segment into a Clojure data structure.</p>
<p>This type of scope cannot be closed, and therefore should not be created in a <a href="null">with-open</a> clause.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L51">view source</a></div></div><div class="public anchor" id="var-copy-segment"><h3>copy-segment</h3><div class="usage"><code>(copy-segment dest src)</code></div><div class="doc"><div class="markdown"><p>Copies the content to <code>dest</code> from <code>src</code></p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L187">view source</a></div></div><div class="public anchor" id="var-defalias"><h3>defalias</h3><h4 class="type">macro</h4><div class="usage"><code>(defalias new-type aliased-type)</code></div><div class="doc"><div class="markdown"><p>Defines a type alias from <code>new-type</code> to <code>aliased-type</code>.</p>
<p>This creates needed serialization and deserialization implementations for the aliased type.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L772">view source</a></div></div><div class="public anchor" id="var-deserialize"><h3>deserialize</h3><div class="usage"><code>(deserialize obj type)</code></div><div class="doc"><div class="markdown"><p>Deserializes an arbitrary type.</p>
<p>For types which have a primitive representation, this deserializes the primitive representation. For types which do not, this deserializes out of a segment.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L629">view source</a></div></div><div class="public anchor" id="var-deserialize*"><h3>deserialize*</h3><h4 class="type">multimethod</h4><div class="usage"></div><div class="doc"><div class="markdown"><p>Deserializes a primitive object into a Clojure data structure.</p>
<p>This is intended for use with types that are returned as a primitive but which need additional processing before they can be returned.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L569">view source</a></div></div><div class="public anchor" id="var-deserialize-from"><h3>deserialize-from</h3><h4 class="type">multimethod</h4><div class="usage"></div><div class="doc"><div class="markdown"><p>Deserializes the given segment into a Clojure data structure.</p>
<p>For types that serialize to primitives, a default implementation will deserialize the primitive before calling <a href="coffi.mem.html#var-deserialize*">deserialize*</a>.</p>
<p>Implementations of this should be inside a <a href="coffi.mem.html#var-with-acquired">with-acquired</a> block for the the <code>segment</code>s scope if they perform multiple memory operations.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L508">view source</a></div></div><div class="public anchor" id="var-global-scope"><h3>global-scope</h3><div class="usage"><code>(global-scope)</code></div><div class="doc"><div class="markdown"><p>Constructs the global scope, which will never reclaim its resources.</p>
<p>This scope may be shared across threads, but is intended mainly in cases where memory is allocated with <a href="coffi.mem.html#var-alloc">alloc</a> but is either never freed or whose management is relinquished to a native library, such as when returned from a callback.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L62">view source</a></div></div><div class="public anchor" id="var-java-layout"><h3>java-layout</h3><div class="usage"><code>(java-layout type)</code></div><div class="doc"><div class="markdown"><p>Gets the Java class to an argument of this type for a method handle.</p>
<p>If a type serializes to a primitive it returns return a Java primitive type. Otherwise, it returns <a href="null">MemorySegment</a>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L339">view source</a></div></div><div class="public anchor" id="var-java-prim-layout"><h3>java-prim-layout</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>Map of primitive type names to the Java types for a method handle.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L326">view source</a></div></div><div class="public anchor" id="var-null.3F"><h3>null?</h3><div class="usage"><code>(null? addr)</code></div><div class="doc"><div class="markdown"><p>Checks if a memory address is null.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L128">view source</a></div></div><div class="public anchor" id="var-primitive-type"><h3>primitive-type</h3><h4 class="type">multimethod</h4><div class="usage"></div><div class="doc"><div class="markdown"><p>Gets the primitive type that is used to pass as an argument for the <code>type</code>.</p>
<p>Implementations of this should be inside a <a href="coffi.mem.html#var-with-acquired">with-acquired</a> block for the the <code>segment</code>s scope if they perform multiple memory operations.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L508">view source</a></div></div><div class="public anchor" id="var-global-scope"><h3>global-scope</h3><div class="usage"><code>(global-scope)</code></div><div class="doc"><div class="markdown"><p>Constructs the global scope, which will never reclaim its resources.</p>
<p>This scope may be shared across threads, but is intended mainly in cases where memory is allocated with <a href="coffi.mem.html#var-alloc">alloc</a> but is either never freed or whose management is relinquished to a native library, such as when returned from a callback.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L62">view source</a></div></div><div class="public anchor" id="var-java-layout"><h3>java-layout</h3><div class="usage"><code>(java-layout type)</code></div><div class="doc"><div class="markdown"><p>Gets the Java class to an argument of this type for a method handle.</p>
<p>If a type serializes to a primitive it returns return a Java primitive type. Otherwise, it returns <a href="null">MemorySegment</a>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L339">view source</a></div></div><div class="public anchor" id="var-java-prim-layout"><h3>java-prim-layout</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>Map of primitive type names to the Java types for a method handle.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L326">view source</a></div></div><div class="public anchor" id="var-null.3F"><h3>null?</h3><div class="usage"><code>(null? addr)</code></div><div class="doc"><div class="markdown"><p>Checks if a memory address is null.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L128">view source</a></div></div><div class="public anchor" id="var-primitive-type"><h3>primitive-type</h3><h4 class="type">multimethod</h4><div class="usage"></div><div class="doc"><div class="markdown"><p>Gets the primitive type that is used to pass as an argument for the <code>type</code>.</p>
<p>This is for objects which are passed to native functions as primitive types, but which need additional logic to be performed during serialization and deserialization.</p>
<p>Implementations of this method should take into account that type arguments may not always be evaluated before passing to this function.</p>
<p>Returns nil for any type which does not have a primitive representation.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L220">view source</a></div></div><div class="public anchor" id="var-primitive.3F"><h3>primitive?</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>A set of all primitive types.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L215">view source</a></div></div><div class="public anchor" id="var-scope-allocator"><h3>scope-allocator</h3><div class="usage"><code>(scope-allocator scope)</code></div><div class="doc"><div class="markdown"><p>Constructs a segment allocator from the given <code>scope</code>.</p>
<p>This is primarily used when working with unwrapped downcall functions. When a downcall function returns a non-primitive type, it must be provided with an allocator.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L72">view source</a></div></div><div class="public anchor" id="var-segment-scope"><h3>segment-scope</h3><div class="usage"><code>(segment-scope segment)</code></div><div class="doc"><div class="markdown"><p>Gets the scope used to construct the <code>segment</code>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L81">view source</a></div></div><div class="public anchor" id="var-seq-of"><h3>seq-of</h3><div class="usage"><code>(seq-of type segment)</code></div><div class="doc"><div class="markdown"><p>Constructs a lazy sequence of <code>type</code> elements deserialized from <code>segment</code>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L641">view source</a></div></div><div class="public anchor" id="var-serialize"><h3>serialize</h3><div class="usage"><code>(serialize obj type)</code><code>(serialize obj type scope)</code></div><div class="doc"><div class="markdown"><p>Serializes an arbitrary type.</p>
<p>For types which have a primitive representation, this serializes into that representation. For types which do not, it allocates a new segment and serializes into that.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L492">view source</a></div></div><div class="public anchor" id="var-serialize*"><h3>serialize*</h3><h4 class="type">multimethod</h4><div class="usage"></div><div class="doc"><div class="markdown"><p>Constructs a serialized version of the <code>obj</code> and returns it.</p>
<p>Returns nil for any type which does not have a primitive representation.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L220">view source</a></div></div><div class="public anchor" id="var-primitive.3F"><h3>primitive?</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>A set of all primitive types.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L215">view source</a></div></div><div class="public anchor" id="var-scope-allocator"><h3>scope-allocator</h3><div class="usage"><code>(scope-allocator scope)</code></div><div class="doc"><div class="markdown"><p>Constructs a segment allocator from the given <code>scope</code>.</p>
<p>This is primarily used when working with unwrapped downcall functions. When a downcall function returns a non-primitive type, it must be provided with an allocator.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L72">view source</a></div></div><div class="public anchor" id="var-segment-scope"><h3>segment-scope</h3><div class="usage"><code>(segment-scope segment)</code></div><div class="doc"><div class="markdown"><p>Gets the scope used to construct the <code>segment</code>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L81">view source</a></div></div><div class="public anchor" id="var-seq-of"><h3>seq-of</h3><div class="usage"><code>(seq-of type segment)</code></div><div class="doc"><div class="markdown"><p>Constructs a lazy sequence of <code>type</code> elements deserialized from <code>segment</code>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L641">view source</a></div></div><div class="public anchor" id="var-serialize"><h3>serialize</h3><div class="usage"><code>(serialize obj type)</code><code>(serialize obj type scope)</code></div><div class="doc"><div class="markdown"><p>Serializes an arbitrary type.</p>
<p>For types which have a primitive representation, this serializes into that representation. For types which do not, it allocates a new segment and serializes into that.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L492">view source</a></div></div><div class="public anchor" id="var-serialize*"><h3>serialize*</h3><h4 class="type">multimethod</h4><div class="usage"></div><div class="doc"><div class="markdown"><p>Constructs a serialized version of the <code>obj</code> and returns it.</p>
<p>Any new allocations made during the serialization should be tied to the given <code>scope</code>, except in extenuating circumstances.</p>
<p>This method should only be implemented for types that serialize to primitives.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L359">view source</a></div></div><div class="public anchor" id="var-serialize-into"><h3>serialize-into</h3><h4 class="type">multimethod</h4><div class="usage"></div><div class="doc"><div class="markdown"><p>Writes a serialized version of the <code>obj</code> to the given <code>segment</code>.</p>
<p>This method should only be implemented for types that serialize to primitives.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L359">view source</a></div></div><div class="public anchor" id="var-serialize-into"><h3>serialize-into</h3><h4 class="type">multimethod</h4><div class="usage"></div><div class="doc"><div class="markdown"><p>Writes a serialized version of the <code>obj</code> to the given <code>segment</code>.</p>
<p>Any new allocations made during the serialization should be tied to the given <code>scope</code>, except in extenuating circumstances.</p>
<p>This method should be implemented for any type which does not override <a href="coffi.mem.html#var-c-layout">c-layout</a>.</p>
<p>For any other type, this will serialize it as <a href="coffi.mem.html#var-serialize*">serialize*</a> before writing the result value into the <code>segment</code>.</p>
<p>Implementations of this should be inside a <a href="coffi.mem.html#var-with-acquired">with-acquired</a> block for the <code>scope</code> if they perform multiple memory operations.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L424">view source</a></div></div><div class="public anchor" id="var-shared-scope"><h3>shared-scope</h3><div class="usage"><code>(shared-scope)</code></div><div class="doc"><div class="markdown"><p>Constructs a new shared scope.</p>
<p>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.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L43">view source</a></div></div><div class="public anchor" id="var-size-of"><h3>size-of</h3><div class="usage"><code>(size-of type)</code></div><div class="doc"><div class="markdown"><p>The size in bytes of the given <code>type</code>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L347">view source</a></div></div><div class="public anchor" id="var-slice"><h3>slice</h3><div class="usage"><code>(slice segment offset)</code><code>(slice segment offset size)</code></div><div class="doc"><div class="markdown"><p>Get a slice over the <code>segment</code> with the given <code>offset</code>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L150">view source</a></div></div><div class="public anchor" id="var-slice-global"><h3>slice-global</h3><div class="usage"><code>(slice-global address size)</code></div><div class="doc"><div class="markdown"><p>Gets a slice of the global address space.</p>
<p>Because this fetches from the global segment, it has no associated scope, and therefore the reference created here cannot prevent the value from being freed. Be careful to ensure that you are not retaining an object incorrectly.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L140">view source</a></div></div><div class="public anchor" id="var-slice-into"><h3>slice-into</h3><div class="usage"><code>(slice-into address segment)</code><code>(slice-into address segment size)</code></div><div class="doc"><div class="markdown"><p>Get a slice into the <code>segment</code> starting at the <code>address</code>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L157">view source</a></div></div><div class="public anchor" id="var-slice-segments"><h3>slice-segments</h3><div class="usage"><code>(slice-segments segment size)</code></div><div class="doc"><div class="markdown"><p>Constructs a lazy seq of <code>size</code>-length memory segments, sliced from <code>segment</code>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L201">view source</a></div></div><div class="public anchor" id="var-stack-scope"><h3>stack-scope</h3><div class="usage"><code>(stack-scope)</code></div><div class="doc"><div class="markdown"><p>Constructs a new scope for use only in this thread.</p>
<p>The memory allocated within this scope is cheap to allocate, like a native stack.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L35">view source</a></div></div><div class="public anchor" id="var-with-acquired"><h3>with-acquired</h3><h4 class="type">macro</h4><div class="usage"><code>(with-acquired scopes &amp; body)</code></div><div class="doc"><div class="markdown"><p>Acquires one or more <code>scopes</code> until the <code>body</code> completes.</p>
<p>This is only necessary to do on shared scopes, however if you are operating on an arbitrary passed scope, it is best practice to wrap code that interacts with it wrapped in this.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L100">view source</a></div></div><div class="public anchor" id="var-with-offset"><h3>with-offset</h3><div class="usage"><code>(with-offset address offset)</code></div><div class="doc"><div class="markdown"><p>Get a new address <code>offset</code> from the old <code>address</code>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/1abc1fd779e86072f502251dec5e9c5350d2ef82/src/clj/coffi/mem.clj#L164">view source</a></div></div></div></body></html>
<p>Implementations of this should be inside a <a href="coffi.mem.html#var-with-acquired">with-acquired</a> block for the <code>scope</code> if they perform multiple memory operations.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L424">view source</a></div></div><div class="public anchor" id="var-shared-scope"><h3>shared-scope</h3><div class="usage"><code>(shared-scope)</code></div><div class="doc"><div class="markdown"><p>Constructs a new shared scope.</p>
<p>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.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L43">view source</a></div></div><div class="public anchor" id="var-size-of"><h3>size-of</h3><div class="usage"><code>(size-of type)</code></div><div class="doc"><div class="markdown"><p>The size in bytes of the given <code>type</code>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L347">view source</a></div></div><div class="public anchor" id="var-slice"><h3>slice</h3><div class="usage"><code>(slice segment offset)</code><code>(slice segment offset size)</code></div><div class="doc"><div class="markdown"><p>Get a slice over the <code>segment</code> with the given <code>offset</code>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L150">view source</a></div></div><div class="public anchor" id="var-slice-global"><h3>slice-global</h3><div class="usage"><code>(slice-global address size)</code></div><div class="doc"><div class="markdown"><p>Gets a slice of the global address space.</p>
<p>Because this fetches from the global segment, it has no associated scope, and therefore the reference created here cannot prevent the value from being freed. Be careful to ensure that you are not retaining an object incorrectly.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L140">view source</a></div></div><div class="public anchor" id="var-slice-into"><h3>slice-into</h3><div class="usage"><code>(slice-into address segment)</code><code>(slice-into address segment size)</code></div><div class="doc"><div class="markdown"><p>Get a slice into the <code>segment</code> starting at the <code>address</code>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L157">view source</a></div></div><div class="public anchor" id="var-slice-segments"><h3>slice-segments</h3><div class="usage"><code>(slice-segments segment size)</code></div><div class="doc"><div class="markdown"><p>Constructs a lazy seq of <code>size</code>-length memory segments, sliced from <code>segment</code>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L201">view source</a></div></div><div class="public anchor" id="var-stack-scope"><h3>stack-scope</h3><div class="usage"><code>(stack-scope)</code></div><div class="doc"><div class="markdown"><p>Constructs a new scope for use only in this thread.</p>
<p>The memory allocated within this scope is cheap to allocate, like a native stack.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L35">view source</a></div></div><div class="public anchor" id="var-with-acquired"><h3>with-acquired</h3><h4 class="type">macro</h4><div class="usage"><code>(with-acquired scopes &amp; body)</code></div><div class="doc"><div class="markdown"><p>Acquires one or more <code>scopes</code> until the <code>body</code> completes.</p>
<p>This is only necessary to do on shared scopes, however if you are operating on an arbitrary passed scope, it is best practice to wrap code that interacts with it wrapped in this.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L100">view source</a></div></div><div class="public anchor" id="var-with-offset"><h3>with-offset</h3><div class="usage"><code>(with-offset address offset)</code></div><div class="doc"><div class="markdown"><p>Get a new address <code>offset</code> from the old <code>address</code>.</p></div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/8e6947392473614d3dbc7d3b6d9878e700bf74e8/src/clj/coffi/mem.clj#L164">view source</a></div></div></div></body></html>