You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Remove __declspec(noalias) from example to make it clearer what is going on.
I'm submitting a second PR that updates __declspec(alias) to have its own example.
Clean up other text.
The compiler will propagate `__declspec(restrict)`. For example, the CRT `malloc` function is decorated with `__declspec(restrict)` and therefore, pointers initialized to memory locations with `malloc` are also implied to not be aliased.
32
+
The compiler will propagate `__declspec(restrict)`. For example, the CRT `malloc` function is decorated with `__declspec(restrict)` and therefore, pointers initialized to memory locations with `malloc` are also implied to not be aliased by previously existing memory.
33
33
34
34
The compiler does not check that the pointer is actually not aliased. It is the developer's responsibility to ensure the program does not alias a pointer marked with the `restrict __declspec` modifier.
35
35
36
-
For similar semantics on variables, see [__restrict](../cpp/extension-restrict.md).
36
+
For similar semantics on variables, see [__restrict](../cpp/extension-restrict.md).
37
+
38
+
For another annotation that can impact aliasing, see also [__declspec(noalias)](../cpp/noalias.md).
37
39
40
+
For information about the restrict keyword that is part of C++ AMP, see [restrict (C++ AMP)](../cpp/restrict-cpp-amp.md).
41
+
38
42
## Example
39
-
See [noalias](../cpp/noalias.md) for an example using `restrict`.
43
+
44
+
The following sample demonstrates using `__declspec(restrict)`.
45
+
46
+
Decorating functions that return pointers with `__declspec(restrict)` tells the compiler that the memory pointed to by the return value is not aliased. In this example, the pointers `mempool` and `memptr` are global so the compiler has no assurance that the memory is not subject to aliasing. However, they are used in such a way that each invocation of `ma` and `init` return memory that isn't otherwise referenced by the program, so `__decslpec(restrict)` is used to help the optimizer. This is similar to how the CRT headers decorate allocation functions such `malloc` as `restrict` to indicate that they always return memory that cannot be aliased by existing pointers.
47
+
48
+
Decorating functions with `__declspec(noalias)` tells the compiler that the function does not interfere with the global state except through the pointers in its parameter list. in the example that accesses memory
0 commit comments