Chinaunix首页 | 论坛 | 博客
  • 博客访问: 993138
  • 博文数量: 200
  • 博客积分: 5011
  • 博客等级: 大校
  • 技术积分: 2479
  • 用 户 组: 普通用户
  • 注册时间: 2008-06-27 15:07
文章分类

全部博文(200)

文章存档

2009年(12)

2008年(190)

我的朋友

分类:

2009-04-02 10:07:49

malloc分配的字节并不是随意的,它能够保证它分配的地址可以被你cast成任何类型的指针来访问,因此malloc应该不会造成align问题的。见如下连接的内容:

amsatishv@gmail.com
Guest
 
Posts: n/a
Default Regarding malloc memory alignment

Hi Group,

I have one question.

If I am allocating memory of 38 bytes to an integer pointer, what will
be the memory actually allocated?

Will there be any memory alignment concept in malloc?

Please let me know the reasons if it is yes / no.

Regards
Ram.
High Speed Die Bonder 4000UPH <10µm Highest Accuracy Die Bonder 0,5µm
Receive a golf alignment tip that could shave 7-12 strokes
Condition Monitoring, TPM/RCM Maintenance suppliers, equipment...
Understand code in less time code-formatting, cross-reference

  #  
Old December 6th, 2007, 04:05 PM
Ben Pfaff
Guest
 
Posts: n/a
Default Re: Regarding malloc memory alignment

writes:
Quote:
I have one question.
It looks like two questions to me.
Quote:
If I am allocating memory of 38 bytes to an integer pointer, what will
be the memory actually allocated?
If you call malloc(38), you will get at least 38 bytes of memory
and possibly more (or no bytes of memory, if the request cannot
be satisfied). How much more depends on your implementation and
possibly on the preexisting state of the system.
Quote:
Will there be any memory alignment concept in malloc?
Memory allocated with malloc is suitably aligned for any standard
C purpose. The C standard says this explicitly:

The pointer returned if the allocation succeeds is suitably
aligned so that it may be assigned to a pointer to any type
of object and then used to access such an object or an array
of such objects in the space allocated (until the space is
explicitly deallocated).
--
"If I've told you once, I've told you LLONG_MAX times not to
exaggerate."
--Jack Klein

阅读(8714) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~