Files
entt/md_docs_2md_2lib.html
2025-03-19 15:49:42 +01:00

143 lines
9.7 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.13.2"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>EnTT: Push EnTT across boundaries</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<script type="text/javascript" src="clipboard.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="cookie.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen-awesome.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr id="projectrow">
<td id="projectalign">
<div id="projectname">EnTT<span id="projectnumber">&#160;3.15.0</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.13.2 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() { codefold.init(0); });
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
initMenu('',true,false,'search.php','Search',false);
$(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function(){ initResizable(false); });
/* @license-end */
</script>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>
</div><!-- top -->
<div id="doc-content">
<div><div class="header">
<div class="headertitle"><div class="title">Push EnTT across boundaries</div></div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p><a class="anchor" id="push-entt-across-boundaries"></a></p>
<h1><a class="anchor" id="table-of-contents-6"></a>
Table of Contents</h1>
<ul>
<li><a class="el" href="#working-across-boundaries">Working across boundaries</a><ul>
<li><a class="el" href="#smooth-until-proven-otherwise">Smooth until proven otherwise</a></li>
<li><a class="el" href="#meta-context">Meta context</a></li>
<li><a class="el" href="#memory-management">Memory management</a></li>
</ul>
</li>
</ul>
<h1><a class="anchor" id="working-across-boundaries"></a>
Working across boundaries</h1>
<p><code>EnTT</code> has historically had a limit when used across boundaries on Windows in general and on GNU/Linux when default visibility was set to hidden. The limitation was mainly due to a custom utility used to assign unique, sequential identifiers with different types.<br />
Fortunately, nowadays <code>EnTT</code> works smoothly across boundaries.</p>
<h2><a class="anchor" id="smooth-until-proven-otherwise"></a>
Smooth until proven otherwise</h2>
<p>Many classes in <code>EnTT</code> make extensive use of type erasure for their purposes. This raises the need to identify objects whose type has been erased.<br />
The <code>type_hash</code> class template is how identifiers are generated and thus made available to the rest of the library. In general, this class arouses little interest. The only exception is when a conflict between identifiers occurs (definitely uncommon though) or when the default solution proposed by <code>EnTT</code> is not suitable for the user's purposes.<br />
The section dedicated to <code>type_info</code> contains all the details to get around the issue in a concise and elegant way. Please refer to the specific documentation.</p>
<p>When working with linked libraries, compile definitions <code>ENTT_API_EXPORT</code> and <code>ENTT_API_IMPORT</code> are to import or export symbols, so as to make everything work nicely across boundaries.<br />
On the other hand, everything should run smoothly when working with plugins or shared libraries that do not export any symbols.</p>
<p>For those who need more details, the test suite contains many examples covering the most common cases (see the <code>lib</code> directory for all details).<br />
It goes without saying that it is impossible to cover <b>all</b> possible cases. However, what is offered should hopefully serve as a basis for all of them.</p>
<h2><a class="anchor" id="meta-context"></a>
Meta context</h2>
<p>The runtime reflection system deserves a special mention when it comes to using it across boundaries.<br />
Since it is linked already to a static context to which the elements are attached and different contexts do not relate to each other, they must be <em>shared</em> to allow the use of meta types across boundaries.</p>
<p>Fortunately, sharing a context is also trivial to do. First of all, the local one is acquired in the main space:</p>
<div class="fragment"><div class="line"><span class="keyword">auto</span> handle = <a class="code hl_function" href="classentt_1_1locator.html#a09b8c4659e08c600c113ce9e5b8fa7d3">entt::locator&lt;entt::meta_ctx&gt;::handle</a>();</div>
<div class="ttc" id="aclassentt_1_1locator_html_a09b8c4659e08c600c113ce9e5b8fa7d3"><div class="ttname"><a href="classentt_1_1locator.html#a09b8c4659e08c600c113ce9e5b8fa7d3">entt::locator::handle</a></div><div class="ttdeci">static node_type handle() noexcept</div><div class="ttdoc">Returns a handle to the underlying service.</div><div class="ttdef"><b>Definition</b> <a href="locator_8hpp_source.html#l00124">locator.hpp:124</a></div></div>
</div><!-- fragment --><p>Then, it is passed to the receiving space that sets it as its default context, thus discarding or storing aside the local one:</p>
<div class="fragment"><div class="line"><a class="code hl_function" href="classentt_1_1locator.html#a51c0f72339094183a1779da8bf01ee22">entt::locator&lt;entt::meta_ctx&gt;::reset</a>(handle);</div>
<div class="ttc" id="aclassentt_1_1locator_html_a51c0f72339094183a1779da8bf01ee22"><div class="ttname"><a href="classentt_1_1locator.html#a51c0f72339094183a1779da8bf01ee22">entt::locator::reset</a></div><div class="ttdeci">static void reset(const node_type &amp;other={}) noexcept</div><div class="ttdoc">Resets or replaces a service.</div><div class="ttdef"><b>Definition</b> <a href="locator_8hpp_source.html#l00134">locator.hpp:134</a></div></div>
</div><!-- fragment --><p>From now on, both spaces refer to the same context and to it are all new meta types attached, no matter where they are created.<br />
Note that <em>replacing</em> the main context does not also propagate changes across boundaries. In other words, replacing a context results in the decoupling of the two sides and therefore a divergence in the contents.</p>
<h2><a class="anchor" id="memory-management"></a>
Memory Management</h2>
<p>There is another subtle problem due to memory management that can lead to headaches.<br />
It can occur where there are pools of objects (such as components or events) dynamically created on demand. This is usually not a problem when working with linked libraries that rely on the same dynamic runtime. However, it can occur in the case of plugins or statically linked runtimes.</p>
<p>As an example, imagine creating an instance of <code>registry</code> in the main executable and sharing it with a plugin. If the latter starts working with a component that is unknown to the former, a dedicated pool is created within the registry on first use.<br />
As one can guess, this pool is instantiated on a different side of the boundary from the <code>registry</code>. Therefore, the instance is now managing memory from different spaces, and this can quickly lead to crashes if not properly addressed.</p>
<p>To overcome the risk, it is recommended to use well-defined interfaces that make fundamental types pass through the boundaries, isolating the instances of the <code>EnTT</code> classes from time to time and as appropriate.<br />
Refer to the test suite for some examples, read the documentation available online about this type of issues or consult someone who has already had such experiences to avoid problems. </p>
</div></div><!-- contents -->
</div><!-- PageDoc -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.13.2
</small></address>
</div><!-- doc-content -->
</body>
</html>