nlib
nn::nlib::exi::ExiAllocatorEx クラスfinal

XmlStreamReader, XmlStreamWriter の各インスタンス毎に設定できるアロケータです。 [詳解]

#include "nn/nlib/exi/ExiAllocator.h"

公開メンバ関数

bool Test (size_t nbytes) noexcept
 nbytes のメモリがアロケート可能かどうかをテストします。 [詳解]
 
size_t GetPos () noexcept
 割り当て済みメモリのサイズを返します。 [詳解]
 
bool IsOutOfMemory () noexcept
 以前のメモリアロケートが失敗したかどうかを調べます。 [詳解]
 
bool IsValid () const noexcept
 アロケータが初期化されていればtrueを返します。
 
 operator bool () const
 アロケータが初期化されていればtrueを返します。
 
基本的なメンバ関数
constexpr ExiAllocatorEx () noexcept
 デフォルトコンストラクタです。
 
 ~ExiAllocatorEx () noexcept
 デストラクタです。
 
 ExiAllocatorEx (const ExiAllocatorEx &rhs) noexcept
 コピーコンストラクタです。
 
ExiAllocatorExoperator= (const ExiAllocatorEx &rhs) noexcept
 代入演算子です。
 
ExiAllocatorExassign (ExiAllocatorEx &rhs, move_tag)
 swapを利用したムーブにより代入します。
 
 ExiAllocatorEx (ExiAllocatorEx &rhs, move_tag)
 swapを利用したムーブによりオブジェクトを構築します。
 
 ExiAllocatorEx (ExiAllocatorEx &&rhs)
 ムーブコンストラクタです。C++11の利用時に有効です。
 
ExiAllocatorExoperator= (ExiAllocatorEx &&rhs)
 ムーブ代入演算子です。C++11の利用時に有効です。
 
void swap (ExiAllocatorEx &rhs) noexcept
 オブジェクトの内容をスワップします。
 
初期化と終了処理
errno_t Init (void *p, size_t size) noexcept
 アロケータを初期化します。 [詳解]
 
void * Finalize () noexcept
 アロケータの利用を終了します。 [詳解]
 
void Reset () noexcept
 アロケータをリセットします。アロケータは初期化直後の状態になります。
 
メモリの割り当てと解放
void * Alloc (size_t nbytes) noexcept
 アロケータからnbytes のメモリを割り当てます。 [詳解]
 
void * Realloc (void *ptr, size_t from_nbytes, size_t nbytes) noexcept
 アロケートされたメモリを拡張する場合に呼び出されることがあります。 [詳解]
 
void Dealloc (void *p) noexcept
 メモリをデアロケートしたときに呼び出されます。 [詳解]
 

詳解

XmlStreamReader, XmlStreamWriter の各インスタンス毎に設定できるアロケータです。

説明
ExiAllocatorはシングルトンですが、ExiAllocatorExはインスタンスを構築でき、XmlStreamReader, XmlStreamWriterの構築時に引数として渡すことにより、(同じスレッドでも)インスタンス毎に異なるアロケータを利用することが可能になります。
メンバ関数はExiAllocatorと同様のものが実装されています。 以下が利用例です。
al_writer.Init(g_WriterBuf, BUF_SIZE);
OutputStream* os = ....;
// Createの第2引数か第3引数にExiAllocatorEx を渡す
UniquePtr<XmlStreamWriter> w(XmlStreamWriter::Create(os, al));

ExiAllocator.h35 行目に定義があります。

関数詳解

◆ Alloc()

nn::nlib::exi::ExiAllocatorEx::Alloc ( size_t  nbytes)
noexcept

アロケータからnbytes のメモリを割り当てます。

引数
[in]nbytesアロケートするメモリのサイズ
戻り値
割り当てられたメモリのアドレス。失敗した場合はNULL

◆ Dealloc()

nn::nlib::exi::ExiAllocatorEx::Dealloc ( void *  p)
noexcept

メモリをデアロケートしたときに呼び出されます。

引数
[in]pデアロケートするメモリの先頭アドレス

◆ Finalize()

nn::nlib::exi::ExiAllocatorEx::Finalize ( )
noexcept

アロケータの利用を終了します。

戻り値
初期化時に与えたメモリブロックのポインタ

◆ GetPos()

nn::nlib::exi::ExiAllocatorEx::GetPos ( )
noexcept

割り当て済みメモリのサイズを返します。

戻り値
割り当て済みメモリのサイズ

◆ Init()

nn::nlib::exi::ExiAllocatorEx::Init ( void *  p,
size_t  size 
)
noexcept

アロケータを初期化します。

引数
[in]pメモリブロックの先頭へのポインタ
[in]sizeメモリブロックのサイズ
戻り値
成功ならば0
説明
アロケータにメモリを割り当て初期化します。

◆ IsOutOfMemory()

nn::nlib::exi::ExiAllocatorEx::IsOutOfMemory ( )
noexcept

以前のメモリアロケートが失敗したかどうかを調べます。

戻り値
メモリのアロケートに失敗していればtrue

◆ Realloc()

nn::nlib::exi::ExiAllocatorEx::Realloc ( void *  ptr,
size_t  from_nbytes,
size_t  nbytes 
)
noexcept

アロケートされたメモリを拡張する場合に呼び出されることがあります。

引数
[in]ptr拡張されるメモリの先頭アドレス
[in]from_nbytes拡張前のアロケートされたメモリサイズ
[in]nbytes拡張後のメモリサイズ
戻り値
割り当てられたメモリのアドレス。失敗した場合はNULL
説明
C標準関数のreallocと違い、現在アロケートされているメモリのサイズを渡す必要があります。

◆ Test()

nn::nlib::exi::ExiAllocatorEx::Test ( size_t  nbytes)
noexcept

nbytes のメモリがアロケート可能かどうかをテストします。

引数
[in]nbytesアロケートしようとするメモリのサイズ
戻り値
falseならばアロケート不可能
説明
falseを返した場合は以後のIsOutOfMemory()の呼び出しがtrueを返します。 Alloc()が失敗するかどうかを事前に知りたい場合に利用します。

このクラス詳解は次のファイルから抽出されました: