From patchwork Tue Nov 26 09:58:20 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Newton X-Patchwork-Id: 21768 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f200.google.com (mail-ie0-f200.google.com [209.85.223.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 998F7202DA for ; Tue, 26 Nov 2013 09:58:26 +0000 (UTC) Received: by mail-ie0-f200.google.com with SMTP id at1sf17949652iec.3 for ; Tue, 26 Nov 2013 01:58:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:message-id:date:from:user-agent :mime-version:to:cc:subject:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe:content-type :content-transfer-encoding; bh=TsQdmyXBtA3l63rxlXuBR9HXt73b/Lez5ehyaFfiNio=; b=YsK6vAKPcAPYGf1nbrf+CAWs98NkXFF0jInhaivKeBhQ4Kn2y2psO52S99RAejoHsh 1vY3CpWHbdv8uNtp6WpMu6wpUrg47VbhRYF6CByCZxpFrsZRmLpwrw0brZi1Rd13492F jm7xrvXRZgvP+ylAEgToFufAdX4Q3gYULg9ZD+NLVoc9j+VnZiGgB8sNhQfArUaRE92T g3EDxsGVoNzXXtmxdEc7ZsxHm5BnlzhwfNYHWIlHg1XvrX7CncdDtR4gnjqdpINKDI2g SLjwkU7rcj1wfA2mjf39HrHej1anIlplXwztXgNfvcRXuK/eaUIhCQDFFblu/MwFNQmu X70A== X-Gm-Message-State: ALoCoQkE6SMJ80qogkosXgf9S+TkCL8NnTk6tZjqOC80tUKppnPIZYg/l9zNjKk9Pbv26d4R0vxX X-Received: by 10.183.3.36 with SMTP id bt4mr10631853obd.29.1385459905515; Tue, 26 Nov 2013 01:58:25 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.109.233 with SMTP id hv9ls2476936qeb.91.gmail; Tue, 26 Nov 2013 01:58:25 -0800 (PST) X-Received: by 10.58.180.227 with SMTP id dr3mr1649848vec.36.1385459905360; Tue, 26 Nov 2013 01:58:25 -0800 (PST) Received: from mail-ve0-f182.google.com (mail-ve0-f182.google.com [209.85.128.182]) by mx.google.com with ESMTPS id h7si19289651vee.33.2013.11.26.01.58.25 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 26 Nov 2013 01:58:25 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.182 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.182; Received: by mail-ve0-f182.google.com with SMTP id jy13so3952317veb.27 for ; Tue, 26 Nov 2013 01:58:25 -0800 (PST) X-Received: by 10.220.86.69 with SMTP id r5mr29788525vcl.9.1385459905257; Tue, 26 Nov 2013 01:58:25 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp199801vcz; Tue, 26 Nov 2013 01:58:24 -0800 (PST) X-Received: by 10.204.96.203 with SMTP id i11mr896692bkn.56.1385459904061; Tue, 26 Nov 2013 01:58:24 -0800 (PST) Received: from mail-bk0-f47.google.com (mail-bk0-f47.google.com [209.85.214.47]) by mx.google.com with ESMTPS id mc8si10612326bkb.216.2013.11.26.01.58.23 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 26 Nov 2013 01:58:24 -0800 (PST) Received-SPF: neutral (google.com: 209.85.214.47 is neither permitted nor denied by best guess record for domain of will.newton@linaro.org) client-ip=209.85.214.47; Received: by mail-bk0-f47.google.com with SMTP id mx12so2442952bkb.20 for ; Tue, 26 Nov 2013 01:58:23 -0800 (PST) X-Received: by 10.205.42.9 with SMTP id tw9mr283742bkb.87.1385459903275; Tue, 26 Nov 2013 01:58:23 -0800 (PST) Received: from localhost.localdomain (cpc6-seac21-2-0-cust453.7-2.cable.virginm.net. [82.1.113.198]) by mx.google.com with ESMTPSA id on10sm50370281bkb.13.2013.11.26.01.58.21 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 26 Nov 2013 01:58:22 -0800 (PST) Message-ID: <529470BC.3080401@linaro.org> Date: Tue, 26 Nov 2013 09:58:20 +0000 From: Will Newton User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.0 MIME-Version: 1.0 To: libc-alpha@sourceware.org CC: Patch Tracking Subject: [PATCH v3 1/2] manual/memory.texi: Bring aligned allocation docs up to date. X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: will.newton@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.182 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The current documentation suggests using memalign and valloc which are now considered obsolete, so suggest using posix_memalign instead. Also document the possible error return and errno values for memalign and posix_memalign and improve documentation of __memalign_hook. ChangeLog: 2013-11-06 Will Newton * manual/memory.texi (Malloc Examples): Clarify default alignment documentation. Suggest posix_memalign rather than memalign or valloc. (Aligned Memory Blocks): Remove suggestion to use memalign or valloc. Remove obsolete comment about BSD. Document memalign errno values and mark the function obsolete. Document posix_memalign returned error codes. Mark valloc as obsolete. (Hooks for Malloc): __memalign_hook is also called for posix_memalign and valloc. (Summary of Malloc): Add posix_memalign to function summary. __memalign_hook is also called for posix_memalign and valloc. --- manual/memory.texi | 61 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 17 deletions(-) Changes in v3: - None. Repost. diff --git a/manual/memory.texi b/manual/memory.texi index a80f87c..3d96f35 100644 --- a/manual/memory.texi +++ b/manual/memory.texi @@ -380,10 +380,10 @@ savestring (const char *ptr, size_t len) The block that @code{malloc} gives you is guaranteed to be aligned so that it can hold any type of data. On @gnusystems{}, the address is -always a multiple of eight on most systems, and a multiple of 16 on +always a multiple of eight on 32-bit systems, and a multiple of 16 on 64-bit systems. Only rarely is any higher boundary (such as a page -boundary) necessary; for those cases, use @code{memalign}, -@code{posix_memalign} or @code{valloc} (@pxref{Aligned Memory Blocks}). +boundary) necessary; for those cases, use @code{posix_memalign} +(@pxref{Aligned Memory Blocks}). Note that the memory located after the end of the block is likely to be in use for something else; perhaps a block already allocated by another @@ -616,14 +616,8 @@ after calling @code{free} wastes memory. The size threshold for The address of a block returned by @code{malloc} or @code{realloc} in @gnusystems{} is always a multiple of eight (or sixteen on 64-bit systems). If you need a block whose address is a multiple of a higher -power of two than that, use @code{memalign}, @code{posix_memalign}, or -@code{valloc}. @code{memalign} is declared in @file{malloc.h} and -@code{posix_memalign} is declared in @file{stdlib.h}. - -With @theglibc{}, you can use @code{free} to free the blocks that -@code{memalign}, @code{posix_memalign}, and @code{valloc} return. That -does not work in BSD, however---BSD does not provide any way to free -such blocks. +power of two than that, use @code{posix_memalign}. @code{posix_memalign} +is declared in @file{stdlib.h}. @comment malloc.h @comment BSD @@ -633,6 +627,21 @@ address is a multiple of @var{boundary}. The @var{boundary} must be a power of two! The function @code{memalign} works by allocating a somewhat larger block, and then returning an address within the block that is on the specified boundary. + +The @code{memalign} function returns a null pointer on error and sets +@code{errno} to one of the following values: + +@table @code +@item ENOMEM +There was insufficient memory available to satisfy the request. + +@item EINVAL +@var{alignment} is not a power of two. + +@end table + +The @code{memalign} function is obsolete and @code{posix_memalign} should +be used instead. @end deftypefun @comment stdlib.h @@ -647,6 +656,16 @@ parameter @var{alignment}: the value must be a power of two multiple of If the function succeeds in allocation memory a pointer to the allocated memory is returned in @code{*@var{memptr}} and the return value is zero. Otherwise the function returns an error value indicating the problem. +The possible error values returned are: + +@table @code +@item ENOMEM +There was insufficient memory available to satisfy the request. + +@item EINVAL +@var{alignment} is not a power of two multiple of @code{sizeof (void *)}. + +@end table This function was introduced in POSIX 1003.1d. @end deftypefun @@ -667,6 +686,9 @@ valloc (size_t size) @ref{Query Memory Parameters} for more information about the memory subsystem. + +The @code{valloc} function is obsolete and @code{posix_memalign} should +be used instead. @end deftypefun @node Malloc Tunable Parameters @@ -902,17 +924,17 @@ memory consumption of the program. @comment malloc.h @comment GNU @defvar __memalign_hook -The value of this variable is a pointer to function that @code{memalign} -uses whenever it is called. You should define this function to look -like @code{memalign}; that is, like: +The value of this variable is a pointer to function that @code{memalign}, +@code{posix_memalign} and @code{valloc} use whenever they are called. +You should define this function to look like @code{memalign}; that is, like: @smallexample void *@var{function} (size_t @var{alignment}, size_t @var{size}, const void *@var{caller}) @end smallexample The value of @var{caller} is the return address found on the stack when -the @code{memalign} function was called. This value allows you to trace the -memory consumption of the program. +the @code{memalign}, @code{posix_memalign} or @code{valloc} functions are +called. This value allows you to trace the memory consumption of the program. @end defvar You must make sure that the function you install as a hook for one of @@ -1118,6 +1140,10 @@ Space}. Allocate a block of @var{size} bytes, starting on a page boundary. @xref{Aligned Memory Blocks}. +@item int posix_memalign (void **@var{memptr}, size_t @var{alignment}, size_t @var{size}) +Allocate a block of @var{size} bytes, starting on an address that is a +multiple of @var{alignment}. @xref{Aligned Memory Blocks}. + @item void *memalign (size_t @var{size}, size_t @var{boundary}) Allocate a block of @var{size} bytes, starting on an address that is a multiple of @var{boundary}. @xref{Aligned Memory Blocks}. @@ -1140,7 +1166,8 @@ A pointer to a function that @code{realloc} uses whenever it is called. A pointer to a function that @code{free} uses whenever it is called. @item void (*__memalign_hook) (size_t @var{size}, size_t @var{alignment}, const void *@var{caller}) -A pointer to a function that @code{memalign} uses whenever it is called. +A pointer to a function that @code{memalign}, @code{posix_memalign} and +@code{valloc} use whenever they are called. @item struct mallinfo mallinfo (void) Return information about the current dynamic memory usage.