C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Proposal for an Extended Memory Management (EMM) Library for the C++Standard

From: Jonathan Wakely <cxx_at_[hidden]>
Date: Fri, 7 Jul 2023 19:12:18 +0100
On Fri, 7 Jul 2023, 19:05 1one1 via Std-Proposals, <
std-proposals_at_[hidden]> wrote:

> **Document number**: PXXXXR0
> **Date**: 2023-07-07
> **Project**: Programming Language C++
> **Reply to**: ahshabazz
>
> # Proposal for an Extended Memory Management (EMM) Library for the C++26
> Standard
>
> ## Introduction
>
> 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.
>
> ## Motivation and Scope
>
> Modern processors heavily rely on cache for performance. A processor'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.
>
> However, currently there is no standard way in C++ to give hints to the
> compiler or the system about a program's memory access patterns. Developers
> must rely on non-standard compiler features or write platform-specific
> code, leading to a lack of portability.
>
> 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.
>
> ## Impact on the Standard
>
> 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.
>
> ## Design Decisions
>
> We propose the addition of two components:
>
> 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.
>
> ```
> #include <cache_control.h> // Hypothetical API header //
> std::emm::data_locality_hint::sequential_access myArray[1000];
> std::vector<int, std::emm::data_locality_hint::random_access> myVector;
>

So this is an allocator? If not, why is it used as the second template
parameter of a vector?

How do you optimise the layout of a vector in memory, when it's required to
be a single contiguous block of memory?

Did you even review the gpt nonsense to see if it made sense?


```
>
> 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.
>

So what does it actually do? How is this "conducted in a high-level" manner?

All you've done is suggest the name of a function. What are its semantics?

Please stop wasting everybody's time.





> ```
> for (int i = 0; i < data.size(); ++i) {
> if (i + 1 < data.size()) {
> std::emm::data_access_hint::prefetch(&data[i + 1]);
> }
>
> // Process data[i] //
> }
> ```
>
> ## Future Directions
>
> If accepted, future extensions to this library could include additional
> memory management features, such as control over memory alignment, page
> size, and more.
>
> ## Acknowledgments
>
> Thanks to the members of the C++ community for their valuable insights and
> discussions that helped shape this proposal.
>
> ## References
>
> [To be added]
>
>
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2023-07-07 18:12:35