man malloc

Sergey Matveychuk sem at FreeBSD.org
Thu Aug 18 08:07:55 GMT 2005


Chuck Swiger wrote:

>> What does "suitable aligned for storage of *any* type of object" means?
> 
> 
> On some platforms, it is either desirable or required that, say, a 
> 8-byte double is stored at a memory location which is is also aligned to 
> 8-bytes:

Oh, it was told for different architectures. It's quite clear for me now.

> 
>> What is pointer coercion? I have no pointer before malloc() returns.
> 
> 
> Right.  Well, malloc returns a (void *), but most people want to use the 
> memory malloc returns to hold their own arrays, structs, whatever, which 
> means that you need to be able to coerce the (void *) malloc gave you 
> into whatever pointer type you want to actually use.
> 
> So the memory malloc gives you needs to be aligned so that it's OK to be 
> used for even the most restrictive datatype known to the system, 
> commonly 8, 16, or 32 bytes.
> 

Pointer coercion means a type cast? I see now.
I read it as 'force change of pointer value' before.

Thanks, guys!
--
Sem.


More information about the freebsd-questions mailing list