From owner-freebsd-questions@FreeBSD.ORG Wed Aug 17 21:45:58 2005 Return-Path: X-Original-To: questions@FreeBSD.org Delivered-To: freebsd-questions@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B207516A41F; Wed, 17 Aug 2005 21:45:58 +0000 (GMT) (envelope-from cswiger@mac.com) Received: from pi.codefab.com (pi.codefab.com [199.103.21.227]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5A8EC43D45; Wed, 17 Aug 2005 21:45:58 +0000 (GMT) (envelope-from cswiger@mac.com) Received: from localhost (localhost [127.0.0.1]) by pi.codefab.com (Postfix) with ESMTP id 86FE75F7B; Wed, 17 Aug 2005 17:45:57 -0400 (EDT) Received: from pi.codefab.com ([127.0.0.1]) by localhost (pi.codefab.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 54680-08; Wed, 17 Aug 2005 17:45:56 -0400 (EDT) Received: from [192.168.1.3] (pool-68-161-79-217.ny325.east.verizon.net [68.161.79.217]) by pi.codefab.com (Postfix) with ESMTP id 175475C74; Wed, 17 Aug 2005 17:45:55 -0400 (EDT) Message-ID: <4303B016.3030201@mac.com> Date: Wed, 17 Aug 2005 17:45:58 -0400 From: Chuck Swiger Organization: The Courts of Chaos User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.11) Gecko/20050801 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Sergey Matveychuk References: <4303A632.1000809@FreeBSD.org> In-Reply-To: <4303A632.1000809@FreeBSD.org> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: amavisd-new at codefab.com Cc: questions@FreeBSD.org Subject: Re: man malloc X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Aug 2005 21:45:58 -0000 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? 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: 0x1000 for example, rather than any of (0x1001, 0x1002, 0x1003, ... 0x1007) > 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. -- -Chuck