From patchwork Tue Nov 26 09:58:30 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Newton X-Patchwork-Id: 21769 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f200.google.com (mail-ve0-f200.google.com [209.85.128.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 9C478202DA for ; Tue, 26 Nov 2013 09:58:35 +0000 (UTC) Received: by mail-ve0-f200.google.com with SMTP id jw12sf13035288veb.7 for ; Tue, 26 Nov 2013 01:58:35 -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=3jsRnNun5Y89M9IVn/uyZkziHeYEG7mPekHRiEyBbyQ=; b=jFm0HRGPslGGCAvSacewGcD6bEK3otU7iZ4eRRiJVAzeLqbDLWybEUnZEsU8kURkfM aCVItksykwLygShGcoYpUbIq0kbSYnnnMNHYt8viEsjFY/TaE/X12RMjFJzraNDk8Eaf 48bxZNfLf9LSYErP/IPtKngiSAxsl/kBW6UrvFGIjKVao1tD1ZhP/I5yTgt5monEW5yI mdCcgMFs3gLNlksZXqizfciB5bU4qdepTIJVdgsCb9MVX0/HVG8OzqqZQz9egtnMNYwn SIAbQtIX1+Q+fa1nNlnDC06uM/Qpdkz+dght0220yrenj810MK6leOrV6B2heBbVHmUm +PFA== X-Gm-Message-State: ALoCoQlew5x3DTRLDJ8Cw2E+SxXfrSApZ0bgrBK+pxINJyUlP6NNWS3NqVsdGR8RK2aoh6Ck3DMl X-Received: by 10.236.114.13 with SMTP id b13mr14980796yhh.37.1385459915202; Tue, 26 Nov 2013 01:58:35 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.131.162 with SMTP id on2ls2468669qeb.73.gmail; Tue, 26 Nov 2013 01:58:35 -0800 (PST) X-Received: by 10.52.168.106 with SMTP id zv10mr25230324vdb.21.1385459915122; Tue, 26 Nov 2013 01:58:35 -0800 (PST) Received: from mail-vc0-f182.google.com (mail-vc0-f182.google.com [209.85.220.182]) by mx.google.com with ESMTPS id k10si19261050vca.124.2013.11.26.01.58.35 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 26 Nov 2013 01:58:35 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.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.220.182; Received: by mail-vc0-f182.google.com with SMTP id lc6so3572914vcb.41 for ; Tue, 26 Nov 2013 01:58:35 -0800 (PST) X-Received: by 10.220.140.4 with SMTP id g4mr1516078vcu.34.1385459914985; Tue, 26 Nov 2013 01:58:34 -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 u4csp199808vcz; Tue, 26 Nov 2013 01:58:34 -0800 (PST) X-Received: by 10.204.195.142 with SMTP id ec14mr398200bkb.80.1385459913967; Tue, 26 Nov 2013 01:58:33 -0800 (PST) Received: from mail-bk0-f54.google.com (mail-bk0-f54.google.com [209.85.214.54]) by mx.google.com with ESMTPS id ci7si10624438bkc.4.2013.11.26.01.58.33 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 26 Nov 2013 01:58:33 -0800 (PST) Received-SPF: neutral (google.com: 209.85.214.54 is neither permitted nor denied by best guess record for domain of will.newton@linaro.org) client-ip=209.85.214.54; Received: by mail-bk0-f54.google.com with SMTP id v16so2433479bkz.41 for ; Tue, 26 Nov 2013 01:58:33 -0800 (PST) X-Received: by 10.204.173.69 with SMTP id o5mr489854bkz.74.1385459913184; Tue, 26 Nov 2013 01:58:33 -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 bf8sm2097603bkb.14.2013.11.26.01.58.31 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 26 Nov 2013 01:58:32 -0800 (PST) Message-ID: <529470C6.6040809@linaro.org> Date: Tue, 26 Nov 2013 09:58:30 +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 2/2] manual/memory.texi: Document aligned_alloc. 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.220.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: , ChangeLog: 2013-11-06 Will Newton * manual/memory.texi (Malloc Examples): Mention aligned_alloc. (Aligned Memory Blocks): Add documentation for aligned_alloc and suggest it as an alternative to posix_memalign. (Hooks for Malloc): Document __memalign_hook is also called for aligned_alloc. (Summary of Malloc): Add summary for aligned alloc. Document __memalign_hook is also called for aligned_alloc. --- manual/memory.texi | 63 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 16 deletions(-) Changes in v3: - Improve documentation of posix_memalign versus aligned_alloc based on review feedback diff --git a/manual/memory.texi b/manual/memory.texi index 3d96f35..55a6a50 100644 --- a/manual/memory.texi +++ b/manual/memory.texi @@ -382,8 +382,8 @@ 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 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{posix_memalign} -(@pxref{Aligned Memory Blocks}). +boundary) necessary; for those cases, use @code{aligned_alloc} or +@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,8 +616,31 @@ 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{posix_memalign}. @code{posix_memalign} -is declared in @file{stdlib.h}. +power of two than that, use @code{aligned_alloc} or @code{posix_memalign}. +@code{aligned_alloc} and @code{posix_memalign} are declared in +@file{stdlib.h}. + +@comment stdlib.h +@deftypefun {void *} aligned_alloc (size_t @var{alignment}, size_t @var{size}) +The @code{aligned_alloc} function allocates a block of @var{size} bytes whose +address is a multiple of @var{alignment}. The @var{alignment} must be a +power of two and @var{size} must be a multiple of @var{alignment}. + +The @code{aligned_alloc} 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. + +This function was introduced in @w{ISO C11} and hence may have better +portability to modern non-POSIX systems than @code{posix_memalign}. +@end table + +@end deftypefun @comment malloc.h @comment BSD @@ -640,8 +663,8 @@ There was insufficient memory available to satisfy the request. @end table -The @code{memalign} function is obsolete and @code{posix_memalign} should -be used instead. +The @code{memalign} function is obsolete and @code{aligned_alloc} or +@code{posix_memalign} should be used instead. @end deftypefun @comment stdlib.h @@ -667,7 +690,9 @@ There was insufficient memory available to satisfy the request. @end table -This function was introduced in POSIX 1003.1d. +This function was introduced in POSIX 1003.1d. Although this function is +superseded by @code{aligned_alloc}, it is more portable to older POSIX +systems that do not support @w{ISO C11}. @end deftypefun @comment malloc.h stdlib.h @@ -687,8 +712,8 @@ 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. +The @code{valloc} function is obsolete and @code{aligned_alloc} or +@code{posix_memalign} should be used instead. @end deftypefun @node Malloc Tunable Parameters @@ -924,17 +949,19 @@ 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}, -@code{posix_memalign} and @code{valloc} use whenever they are 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{aligned_alloc}, +@code{memalign}, @code{posix_memalign} and @code{valloc} use whenever they +are called. You should define this function to look like @code{aligned_alloc}; +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}, @code{posix_memalign} or @code{valloc} functions are -called. This value allows you to trace the memory consumption of the program. +the @code{aligned_alloc}, @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 @@ -1140,6 +1167,10 @@ Space}. Allocate a block of @var{size} bytes, starting on a page boundary. @xref{Aligned Memory Blocks}. +@item void *aligned_alloc (size_t @var{size}, size_t @var{alignment}) +Allocate a block of @var{size} bytes, starting on an address that is a +multiple of @var{alignment}. @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}. @@ -1166,8 +1197,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}, @code{posix_memalign} and -@code{valloc} use whenever they are called. +A pointer to a function that @code{aligned_alloc}, @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.