GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cpprefjp - C++日本語リファレンス
  • GitHub Project

This view

  • Original page
  • New address

GeezerVison is showing cpprefjp.github.io — std::aligned_alloc - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. cstdlib
  3. aligned_alloc

最終更新日時: 2024年06月11日 22時45分38秒 (JST)
Akira Takahashi が更新

履歴 編集

function
<cstdlib>

std::aligned_alloc(C++17)

namespace std {
  void* aligned_alloc(size_t alignment, size_t size);
}

概要

指定したアライメントでメモリを確保する。

事前条件

  • 指定するアライメント値alignmentは、実装がサポートしている有効なアライメント値であること
    • POSIXの実装では、2の累乗、およびsizeof(void*)の倍数であること
  • サイズ値sizeは、alignmentの整数倍であること

効果

指定されたアライメントで、size分の不定値領域を確保する。

戻り値

確保した領域へのポインタを返す。

確保できなかった場合、ヌルポインタを返す。

例

#include <cstdlib>

int main()
{
  // 8バイトアライメントで、16バイトの領域を確保する
  void* p = std::aligned_alloc(8, 16);
  std::free(p);
}

出力

バージョン

言語

  • C++17

処理系

  • Clang: 3.4 ✅
  • GCC: 8.3 ✅
  • Visual C++: 2019 Update 3 ❌

備考

  • Clangは、グローバル名前空間 (POSIXの実装) では、3.1で動作確認できた
  • GCCは、グローバル名前空間 (POSIXの実装) では、4.4で動作確認できた
  • Visual Studio 2019 Update 3の時点では存在が確認できない。_aligned_mallocという同等のWindows用機能が提供されているため、そちらを使う必要がある

参照

  • aligned_alloc(3) - Linux man page
  • P0063R3 C++17 should refer to C11 instead of C99
  • P0175R1 Synopses for the C library
  • C ++ 17 std :: aligned_alloc缺失-C ++ 17 Std :: aligned_alloc欠落
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.