Skip to content

Latest commit

 

History

History
65 lines (50 loc) · 2.14 KB

File metadata and controls

65 lines (50 loc) · 2.14 KB

release

  • memory_resource[meta header]
  • function[meta id-type]
  • std::pmr[meta namespace]
  • monotonic_buffer_resource[meta class]
  • cpp17[meta cpp]
void release();

概要

管理している全てのメモリを解放する。

効果

必要に応じてthis->upstream_resource()->deallocate()を呼び出し上流メモリリソースから割り当てた全てのメモリを解放する。
deallocate()によって割り当て解除されていないメモリがあったとしても、全てのメモリが解放される。

コンストラクタから設定された初期メモリ領域の解放は行われない。

#include <iostream>
#include <memory_resource>

int main() {

  std::pmr::monotonic_buffer_resource mr{};

  //メモリを確保
  auto* p1 = mr.allocate(sizeof(int), alignof(int));
  auto* p2 = mr.allocate(sizeof(int), alignof(int));

  //解放せずにrelease
  mr.release();
  //以降、p1,p2の領域にアクセスしてはならない
}
  • release[color ff0000]
  • allocate[link /reference/memory_resource/memory_resource/allocate.md]
  • monotonic_buffer_resource[link /reference/memory_resource/monotonic_buffer_resource.md]

出力

バージョン

言語

  • C++17

処理系

関連項目

参照