<div dir="auto"><div><br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 7 Jul 2023, 19:05 1one1 via Std-Proposals, &lt;<a href="mailto:std-proposals@lists.isocpp.org">std-proposals@lists.isocpp.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>
<div>**Document number**: PXXXXR0  </div><div>**Date**: 2023-07-07  </div><div>**Project**: Programming Language C++  </div><div>**Reply to**: ahshabazz</div><div><br></div><div># Proposal for an Extended Memory Management (EMM) Library for the C++26 Standard</div><div><br></div><div>## Introduction</div><div><br></div><div>This paper proposes the addition of an extended memory management library to the C++ Standard Library. This library will provide developers with a standard way to give hints about memory access patterns and prefetching, allowing for potential improvements in cache efficiency and overall performance.</div><div><br></div><div>## Motivation and Scope</div><div><br></div><div>Modern processors heavily rely on cache for performance. A processor&#39;s cache is used to store data that is likely to be used in the near future, with the aim of reducing memory latency. The effectiveness of cache relies on the locality of memory accesses, both in time (temporal locality) and in space (spatial locality). Thus, the way a program accesses memory can significantly impact its performance.</div><div><br></div><div>However, currently there is no standard way in C++ to give hints to the compiler or the system about a program&#39;s memory access patterns. Developers must rely on non-standard compiler features or write platform-specific code, leading to a lack of portability.</div><div><br></div><div>By introducing an extended memory management library, we can provide a standard, platform-independent way for developers to optimize their memory access patterns, potentially improving cache efficiency and performance.</div><div><br></div><div>## Impact on the Standard</div><div><br></div><div>This proposal is purely additive and does not modify any existing parts of the C++ Standard. It does not require any changes to the core language.</div><div><br></div><div>## Design Decisions</div><div><br></div><div>We propose the addition of two components:</div><div><br></div><div>1. **Data Locality Optimizations API:** This API allows developers to give hints about memory access patterns. These hints can potentially be used by the system to optimize the layout of data structures in memory.</div><div><br></div><div>```</div><div>#include &lt;cache_control.h&gt; // Hypothetical API header // </div><div>std::emm::data_locality_hint::sequential_access myArray[1000];</div><div>std::vector&lt;int, std::emm::data_locality_hint::random_access&gt; myVector;</div></div></blockquote></div></div><div dir="auto"><br></div><div dir="auto">So this is an allocator? If not, why is it used as the second template parameter of a vector?</div><div dir="auto"><br></div><div dir="auto">How do you optimise the layout of a vector in memory, when it&#39;s required to be a single contiguous block of memory?</div><div dir="auto"><br></div><div dir="auto">Did you even review the gpt nonsense to see if it made sense?</div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>```</div><div><br></div><div>2. **Prefetching API:** This API allows developers to give hints about future memory accesses, potentially enabling the system to prefetch data into cache ahead of time, similar to the compiler specific __builtin_prefetch in GCC, however now conducted in a high level platform-independent manner.</div></div></blockquote></div></div><div dir="auto"><br></div><div dir="auto">So what does it actually do? How is this &quot;conducted in a high-level&quot; manner?</div><div dir="auto"><br></div><div dir="auto">All you&#39;ve done is suggest the name of a function. What are its semantics?</div><div dir="auto"><br></div><div dir="auto">Please stop wasting everybody&#39;s time.</div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><br></div><div>```</div><div>for (int i = 0; i &lt; data.size(); ++i) {</div><div>    if (i + 1 &lt; data.size()) {</div><div>        std::emm::data_access_hint::prefetch(&amp;data[i + 1]);</div><div>    }</div><div><br></div><div>    // Process data[i] //</div><div>}</div><div>```</div><div><br></div><div>## Future Directions</div><div><br></div><div>If accepted, future extensions to this library could include additional memory management features, such as control over memory alignment, page size, and more.</div><div><br></div><div>## Acknowledgments</div><div><br></div><div>Thanks to the members of the C++ community for their valuable insights and discussions that helped shape this proposal.</div><div><br></div><div>## References</div><div><br></div><div>[To be added]</div><br><br><div><br></div>
</div>-- <br>
Std-Proposals mailing list<br>
<a href="mailto:Std-Proposals@lists.isocpp.org" target="_blank" rel="noreferrer">Std-Proposals@lists.isocpp.org</a><br>
<a href="https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals" rel="noreferrer noreferrer" target="_blank">https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals</a><br>
</blockquote></div></div></div>

