游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2475|回复: 4

vc里的malloc库函数是否保证返回对齐的内存地址?

[复制链接]

1

主题

49

帖子

49

积分

注册会员

Rank: 2

积分
49
发表于 2011-3-29 18:59:00 | 显示全部楼层 |阅读模式
rt..

1

主题

49

帖子

49

积分

注册会员

Rank: 2

积分
49
 楼主| 发表于 2011-3-29 19:55:00 | 显示全部楼层

Re:vc里的malloc库函数是否保证返回对齐的内存地址?

搞清楚了,问这个问题是因为经常看到类似aligned_allocator的专用类.

malloc() is supposed to return a pointer that is sufficiently well aligned for any purpose. However, the meaning of 'any' is primarily for things like basic types - long, double, long double, long long. When you are doing more specialized things, like playing with graphics systems, they can need more stringent alignment than the rest of the system

11

主题

1238

帖子

1782

积分

金牌会员

Rank: 6Rank: 6

积分
1782
发表于 2011-3-30 13:03:00 | 显示全部楼层

Re:vc里的malloc库函数是否保证返回对齐的内存地址?

别用VC了,用这个
http://www.gnu.org/software/libtool/manual/libc/Aligned-Memory-Blocks.html

1

主题

49

帖子

49

积分

注册会员

Rank: 2

积分
49
 楼主| 发表于 2011-3-30 19:03:00 | 显示全部楼层

Re:vc里的malloc库函数是否保证返回对齐的内存地址?

那个32位下怎么是8byte对齐,4byte不就行了吗...

1

主题

49

帖子

49

积分

注册会员

Rank: 2

积分
49
 楼主| 发表于 2011-3-30 19:42:00 | 显示全部楼层

Re:vc里的malloc库函数是否保证返回对齐的内存地址?

我想了一下,这个问题可能不只跟cpu访问内存次数有关,也跟cpu的高速缓冲机制有关.
如果不是按照double来对齐的话,可能会刷新两条cache line.

望高手解答.
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-6-8 05:52

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表