This repository has been archived by the owner on Sep 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
A.Proposal.for.an.Extended.Memory,Management.Library.cpp
58 lines (36 loc) · 2.85 KB
/
A.Proposal.for.an.Extended.Memory,Management.Library.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
**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;
```
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.
```
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]