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::align - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. memory
  3. align

最終更新日時: 2026年09月16日 21時49分06秒 (JST)
rotarymars が更新

履歴 編集

function
<memory>

std::align(C++11)

namespace std {
  void* align(std::size_t alignment, std::size_t size,
              void*& ptr, std::size_t& space);
}

概要

アライメント調整された領域を得る。

効果

範囲[ptr, ptr + space)の中にalignmentバイトでアライメント調整された領域のsizeバイトに一致するバッファがあるなら、

  • ptrを一致する領域の先頭アドレスへと更新し、
  • spaceから使用したバイト数を減算する。

そのようなバッファがなければ、この関数は何もしない。

戻り値

更新されたptrを返す。一致する領域がなければ、ヌルポインタを返す。

例

#include <iostream>
#include <memory>

int main()
{
  char buffer[256];
  void* ptr = buffer;
  std::size_t space = sizeof(buffer) - 1;

  // intアライメントで、intをN個確保。
  std::size_t N = 3;
  if (std::align(alignof(int), sizeof(int) * N, ptr, space)) {
    std::cout << ptr << " " << space << std::endl;
  }
}

出力例

0x7fffd930ca40 255

バージョン

言語

  • C++11

処理系

  • Clang: 3.0 ✅
  • GCC: 5.0 ✅
  • Visual C++: 2012 ✅, 2013 ✅
    • 2012はマニュアル(MSDNライブラリ)に記載がないものの、実装されている。
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.