| |

VerySource

 Forgot password?
 Register
Search
View: 660|Reply: 4

What is automatic alignment when allocating space?

[Copy link]

7

Threads

15

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-1-31 14:20:01
| Show all posts |Read mode
When asking the teacher's linked list, the teacher mentioned that when allocating space, it was not simple addition, and automatic alignment or something.
Reply

Use magic Report

0

Threads

32

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 Invalid IP Address

Post time: 2020-3-10 15:15:01
| Show all posts
For example, when you format a hard disk, you usually have the file system option and the size of the smallest allocation unit. If the minimum allocation unit is 16 K, it means that you have created a new file, even if you only wrote , The system will also allocate 16 K of hard disk space for you.

The memory is the same.In order to facilitate memory management, the smallest allocation unit is generally selected, such as 32 bit.If you declare a char-type variable, it originally thought that it only took up 1 byte of space, in fact it took up 4 bytes.
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-3-16 15:15:01
| Show all posts
struct A
{
 char a;
 int b;
};
struct B
{
 int a;
 int b;
};
sizeof (A) == sizeof (B) == 8
char is padded to int (default 4 bytes)
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-3-26 12:45:01
| Show all posts
A data access optimization technology for the compiler, which can be set by compiler instructions
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-28 17:45:01
| Show all posts
This is also called data alignment, and it is explained in a section in "Windows Core Programming".
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list