64位机器上的字符大小 [英] Size of char on a 64 bit machine

查看:145
本文介绍了64位机器上的字符大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将字符存储在单词对齐的机器中?假设64bit

机器,1字节是为char保留的,是否只有1

字节用于存储字符,其余7字节被浪费,

或我的假设是错的?如果我的假设是正确的,那么在检索字符变量的值时,

的性能问题是什么呢?
其他数据类型如整数,双精度或浮点数。

How is a character stored in a word aligned machine? Assuming on 64bit
machine, 1 byte is reserved for a char, is it the case that only 1
byte is used to store the character and the rest 7 bytes are wasted,
or my assumption is wrong? If my assumption is right, what are the
performance issues in retrieving value of a character variable over
other data types like integer, double or float.

推荐答案

aruna写道:
aruna wrote:
如何将字符存储在单词对齐的机器中?


取决于机器。

假设在64位机器上,1字节是为char保留的,是否只有1
字节用于存储字符,剩下的7个字节是浪费,
或我的假设是错误的?


您的假设可能是错误的,但这取决于机器。

如果我的假设是正确的,检索中的性能问题是什么?字符变量的值超过其他数据类型,如整数,双精度或浮点数。
How is a character stored in a word aligned machine?
Depends on the machine.
Assuming on 64bit
machine, 1 byte is reserved for a char, is it the case that only 1
byte is used to store the character and the rest 7 bytes are wasted,
or my assumption is wrong?
Your assumption is probably wrong, but it depends on the machine.
If my assumption is right, what are the
performance issues in retrieving value of a character variable over
other data types like integer, double or float.




这取决于机器。


基本上,通常,但不一定:数组中的字符是

通常按顺序存储,中间没有任何填充。可以

在无符号字符中没有填充。


这些不是关于C的问题,而是关于C实现的问题。


-

托马斯。



That depends on the machine.

Essentially, usually, but not necessarily: Characters in an array are
usually stored sequentially without any padding in between. There can
be no padding in unsigned char.

These are not questions about C, but about C implementations.

--
Thomas.


aruna写道:

如何是一个存储在单词对齐机器中的字符?假设在64位机器上,为字符保留1个字节,是否只有1个字节用于存储字符,其余7个字节被浪费,
或我的假设是错的?如果我的假设是正确的,那么在检索字符变量的值时会有什么性能问题呢?其他数据类型如整数,双精度或浮点数。

How is a character stored in a word aligned machine? Assuming on 64bit
machine, 1 byte is reserved for a char, is it the case that only 1
byte is used to store the character and the rest 7 bytes are wasted,
or my assumption is wrong? If my assumption is right, what are the
performance issues in retrieving value of a character variable over
other data types like integer, double or float.




C语言无法回答这些问题

本身,但仅限于它的特定实现。

不同的实现将以不同的方式做事,并且

他们不同的选择会导致不同的答案。


-
Er ********* @ sun.com


" aruna" < AR ******** @ yahoo.co.in>在留言中写道

新闻:a2 ************************** @ posting.google.c om ...
"aruna" <ar********@yahoo.co.in> wrote in message
news:a2**************************@posting.google.c om...
如何将字符存储在单词对齐的机器中?


你的意思是一台机器,所有变量,无论大小,都必须存储

,8字节对齐?我不知道这样的机器,但如果有一台机器,你的假设是正确的。


通常的情况是变量必须对齐按照自己的规模,例如a
char只需要1字节对齐,但32位int需要4字节
对齐。根据你的变量最终在内存中的排列方式,它可能会在同一个64位字中结束。

假设在64位
机器,为字符保留1个字节,是否只有1个字节用于存储字符,其余7个字节被浪费,
或我的假设是错误的?如果我的假设是正确的,那么在检索字符变量的值时会有什么性能问题呢?其他数据类型如整数,双精度或浮点数。
How is a character stored in a word aligned machine?
You mean a machine where all variables, regardless of size, must be stored
with 8-byte alignment? I''m not aware of such a machine, but if one exists
your assumption would be correct.

The usual case is that variables must be aligned to their own size, e.g. a
char requires only 1-byte alignment, but a 32-bit int requires 4-byte
alignment. Depending on how your variables end up laid out in memory, it''s
possible several may end up in the same 64-bit word.
Assuming on 64bit
machine, 1 byte is reserved for a char, is it the case that only 1
byte is used to store the character and the rest 7 bytes are wasted,
or my assumption is wrong? If my assumption is right, what are the
performance issues in retrieving value of a character variable over
other data types like integer, double or float.




现代处理器对于所有负载具有相同的延迟,最大值为单个缓存行的大小。但是,在每个缓存行中使用多个变量可以获得很大的性能优势,因为它可以减少缓存未命中。


S

-

Stephen Sprunk愚蠢的人用智能环绕自己

CCIE#3723人。聪明的人围绕着他们自己与他们不同意的K5SSS聪明人。 --Aaron Sorkin



Modern processors have the same latency for all loads up to the size of a
single cache line. However, there is a large performance benefit in having
multiple variables in each cache line because it reduces cache misses.

S

--
Stephen Sprunk "Stupid people surround themselves with smart
CCIE #3723 people. Smart people surround themselves with
K5SSS smart people who disagree with them." --Aaron Sorkin


这篇关于64位机器上的字符大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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