Date: Wed, 17 Aug 2005 23:32:44 +0200 From: Erik Trulsson <ertr1013@student.uu.se> To: Sergey Matveychuk <sem@FreeBSD.org> Cc: questions@FreeBSD.org Subject: Re: man malloc Message-ID: <20050817213243.GA26065@falcon.midgard.homeip.net> In-Reply-To: <4303A632.1000809@FreeBSD.org> References: <4303A632.1000809@FreeBSD.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Aug 18, 2005 at 01:03:46AM +0400, Sergey Matveychuk wrote: > I know it may be stupid, but I can't understand this sentence from > malloc(3) man page: > > " > The allocated space is suitably aligned (after possible pointer > coercion) for storage of any type of object. > " > > What does "suitable aligned for storage of *any* type of object" means? In what way is that difficult to understand? It can't really be expressed any simpler, and it means exactly what it says: That the storage allocated by malloc is suitably aligned for storing any kind of object. As an example, it is not uncommon for many systems to require that a 32-bit integer must be aligned on a 4-byte boundary. (I.e. if the CPU tries to access such an object placed on an address that is not a multiple of 4, then the program will crash.) Exactly what alignment is required for different objects can vary quite a bit, but malloc guarantees that the storage it allocates is aligned in such a way that you can store any kind object in it (assuming it is large enough, of course.) > What is pointer coercion? No idea. It is not standard terminology anway. > I have no pointer before malloc() returns. Then where do you store the value returned by malloc? You almost certainly do have some pointer even before malloc returns, but that pointer might not contain any useful value. -- <Insert your favourite quote here.> Erik Trulsson ertr1013@student.uu.se
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050817213243.GA26065>