malloc(allocator)由8或16字节对齐 [英] malloc(allocator) aligned by 8 or 16 byte

查看:427
本文介绍了malloc(allocator)由8或16字节对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么malloc(分配器)保证由它们返回的地址将由8字节(在32位机器上)或16字节(64位机器)对齐?

why malloc (allocator) guarantees that address return by them will be
aligned by 8 byte ( on 32bit machin ) or 16 byte (64 bit machin) ?

推荐答案

shaanxxx写道:
shaanxxx wrote:

为什么malloc(allocator)保证他们返回的地址将是

由8字节(在32位机器上)或16字节(64位机器)对齐?
why malloc (allocator) guarantees that address return by them will be
aligned by 8 byte ( on 32bit machin ) or 16 byte (64 bit machin) ?



它没有。它保证地址适合任何类型。

必须是这种情况,因为malloc返回一个void *,它可以分配给任何指针类型。

。 />

-

Ian Collins。

It doesn''t. It guarantees the address is suitably aligned for any type.
This has to be the case because malloc returns a void* which can be
assigned to any pointer type.

--
Ian Collins.


shaanxxx说:
shaanxxx said:

为什么malloc(分配器)保证它们返回的地址将是8字节(在32位机器上)或16字节(64位机器)对齐的

why malloc (allocator) guarantees that address return by them will be
aligned by 8 byte ( on 32bit machin ) or 16 byte (64 bit machin) ?



C语言标准没有这样的保证。


-

Richard Heathfield< ; http://www.cpax.org.uk>

电子邮件:-www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - dmr 1999年7月29日

The C language standard makes no such guarantee.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


文章< 11 ********************** @ 50g2000hsm。 Google网上论坛。 com>,

shaanxxx< sh ****** @ yahoo.comwrote:
In article <11**********************@50g2000hsm.googlegroups. com>,
shaanxxx <sh******@yahoo.comwrote:

>为什么malloc(allocator)保证它们返回的地址将由8字节(在32位机器上)或16字节(64位机器)对齐?
>why malloc (allocator) guarantees that address return by them will be
aligned by 8 byte ( on 32bit machin ) or 16 byte (64 bit machin) ?



据推测,在这些系统上,对象必须在8或16字节边界上对齐
。例如,

double很可能是8字节长,并且必须是8字节对齐。即使它没有* * b $ b也没有*对齐,如果它可能更有效。

这因系统而异 - 你可以''依靠它。


因为malloc()不知道你要在内存中存储什么样的对象

必须确保它与任何类型对齐(或者至少为
,适合任何类型)。


我无法猜测它是什么类型的64位机器需要

16字节对齐。


- 理查德

-

考虑在一些字母表中需要多达32个字符

- 1963年的X3.4。

Presumably on those systems there are objects that have to be aligned
on 8- or 16- byte boundaries. For example, it''s quite likely that a
double is 8 bytes long and has to be 8-byte aligned. Even if it
doesn''t *have* to be aligned, it may be more efficient if it is.
This varies from system to system - you can''t rely on it.

Since malloc() doesn''t know what kind of object you''re going to store
in the memory, it has to make sure it''s aligned for any kind (or at
least, any kind that will fit).

I can''t guess what type it is on the 64-bit machine that requires
16-byte alignment.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.


这篇关于malloc(allocator)由8或16字节对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆