Skip to content

Commit 0625721

Browse files
author
mikeblome
committed
fixed links
1 parent 748d9e8 commit 0625721

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

‎docs/cpp/alignment-cpp-declarations.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ ms.assetid: a986d510-ccb8-41f8-b905-433df9183485
77
---
88
# Alignment
99

10-
One of the low-level features of C++ is the ability to specify the precise alignment of objects in memory to take maximum advantage of a specific hardware architecture. By default, the compiler aligns class and struct members on their size value: `bool` and `char` on 1-byte boundaries, `short` on 2-byte boundaries, `int`, `long`, and `float` on 4-byte boundaries, and `long long`, `double`, and `long double` on 8-byte boundaries. In most scenarios, you never have to be concerned with alignment because the default alignment is already optimal. In some cases, however, you can achieve significant performance improvements, or memory savings, by specifying a custom alignment for your data structures. Before Visual Studio 2015 you could use the Microsoft-specific keywords `__alignof` and `declspec(alignas)` to specify an alignment greater than the default. Starting in Visual Studio 2015 you should use the C++11 standard keywords [alignof and alignas](../cpp/alignof-and-alignas-cpp.md) for maximum code portability. The new keywords behave in the same way under the hood as the Microsoft-specific extensions. The documentation for those extensions also applies to the new keywords. For more information, see [__alignof Operator](../cpp/alignof-operator.md) and [align](../cpp/align-cpp.md). The C++ standard doesn't specify packing behavior for alignment on boundaries smaller than the compiler default for the target platform, so you still need to use the Microsoft #pragma [pack](../preprocessor/pack.md) in that case.
10+
One of the low-level features of C++ is the ability to specify the precise alignment of objects in memory to take maximum advantage of a specific hardware architecture. By default, the compiler aligns class and struct members on their size value: `bool` and `char` on 1-byte boundaries, `short` on 2-byte boundaries, `int`, `long`, and `float` on 4-byte boundaries, and `long long`, `double`, and `long double` on 8-byte boundaries.
11+
12+
In most scenarios, you never have to be concerned with alignment because the default alignment is already optimal. In some cases, however, you can achieve significant performance improvements, or memory savings, by specifying a custom alignment for your data structures. Before Visual Studio 2015 you could use the Microsoft-specific keywords `__alignof` and `declspec(alignas)` to specify an alignment greater than the default. Starting in Visual Studio 2015 you should use the C++11 standard keywords **alignof** and **alignas** for maximum code portability. The new keywords behave in the same way under the hood as the Microsoft-specific extensions. The documentation for those extensions also applies to the new keywords. For more information, see [__alignof Operator](../cpp/alignof-operator.md) and [align](../cpp/align-cpp.md). The C++ standard doesn't specify packing behavior for alignment on boundaries smaller than the compiler default for the target platform, so you still need to use the Microsoft #pragma [pack](../preprocessor/pack.md) in that case.
1113

1214
Use the [aligned_storage class](../standard-library/aligned-storage-class.md) for memory allocation of data structures with custom alignments. The [aligned_union class](../standard-library/aligned-union-class.md) is for specifying alignment for unions with non-trivial constructors or destructors.
1315

14-
## About alignment
16+
## Alignment and memory addresses
1517

1618
Alignment is a property of a memory address, expressed as the numeric address modulo a power of 2. For example, the address 0x0001103F modulo 4 is 3. That address is said to be aligned to 4n+3, where 4 indicates the chosen power of 2. The alignment of an address depends on the chosen power of 2. The same address modulo 8 is 7. An address is said to be aligned to X if its alignment is Xn+0.
1719

@@ -88,6 +90,7 @@ adr offset element
8890
0x0022 char d;
8991
0x0023 char _pad1[1];
9092
```
93+
9194
## alignof and alignas
9295

9396
The **alignas** type specifier is a portable, C++ standard way to specify custom alignment of variables and user defined types. The **alignof** operator is likewise a standard, portable way to obtain the alignment of a specified type or variable.

‎docs/cpp/basic-concepts-cpp.md‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ This section explains concepts that are critical to understanding C++. C program
1818
- [Lvalues and rvalues](lvalues-and-rvalues-visual-cpp.md)
1919
- [Temporary objects](temporary-objects.md)
2020
- [Alignment](alignment-cpp-declarations.md)
21-
- [alignof and alignas](alignof-and-alignas-cpp.md)
2221
- [Trivial, standard-layout and POD types](trivial-standard-layout-and-pod-types.md)
2322

2423
## See also

‎docs/standard-library/alignment-of-class.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
22
title: "alignment_of Class"
3-
ms.date: "11/04/2016"
3+
ms.date: "12/11/2019"
44
f1_keywords: ["type_traits/std::alignment_of"]
55
helpviewer_keywords: ["alignment_of class", "alignment_of"]
66
ms.assetid: 4141c59a-f94e-41c4-93fd-9ea578b27387
77
---
88
# alignment_of Class
99

10-
Gets alignment of the specified type. This struct is implemented in terms of [alignof](../cpp/alignof-and-alignas-cpp.md). Use `alignof` directly when you simply need to query an alignment value. Use alignment_of when you need an integral constant, for example when doing tag dispatch.
10+
Gets alignment of the specified type. This struct is implemented in terms of [alignof](../cpp/alignment-cpp-declarations.md). Use **alignof** directly when you simply need to query an alignment value. Use alignment_of when you need an integral constant, for example when doing tag dispatch.
1111

1212
## Syntax
1313

0 commit comments

Comments
 (0)