Skip to content

Add remark about _aligned_malloc and free #1778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docs/c-runtime-library/reference/aligned-malloc.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "_aligned_malloc"
ms.date: "11/04/2016"
ms.date: "12/11/2019"
api_name: ["_aligned_malloc"]
api_location: ["msvcrt.dll", "msvcr80.dll", "msvcr90.dll", "msvcr100.dll", "msvcr100_clr0400.dll", "msvcr110.dll", "msvcr110_clr0400.dll", "msvcr120.dll", "msvcr120_clr0400.dll", "ucrtbase.dll", "api-ms-win-crt-heap-l1-1-0.dll"]
api_type: ["DLLExport"]
Expand Down Expand Up @@ -42,6 +42,8 @@ A pointer to the memory block that was allocated or NULL if the operation failed

This function sets `errno` to `ENOMEM` if the memory allocation failed or if the requested size was greater than `_HEAP_MAXREQ`. For more information about `errno`, see [errno, _doserrno, _sys_errlist, and _sys_nerr](../../c-runtime-library/errno-doserrno-sys-errlist-and-sys-nerr.md). Also, **_aligned_malloc** validates its parameters. If *alignment* is not a power of 2 or *size* is zero, this function invokes the invalid parameter handler, as described in [Parameter Validation](../../c-runtime-library/parameter-validation.md). If execution is allowed to continue, this function returns NULL and sets `errno` to `EINVAL`.

Use [_aligned_free](aligned-free.md) to deallocate memory obtained by both **_aligned_malloc** and `_aligned_offset_malloc`. Don't use `free`, which doesn't reclaim the aligned memory correctly and can lead to hard-to-diagnose bugs.

## Requirements

|Routine|Required header|
Expand Down Expand Up @@ -132,4 +134,4 @@ This pointer, 3280891, is offset by 5 on alignment of 16

## See also

[Data Alignment](../../c-runtime-library/data-alignment.md)
[Data Alignment](../../c-runtime-library/data-alignment.md)