Skip to content

Instantly share code, notes, and snippets.

@harujoh
Last active December 3, 2021 07:18
Show Gist options
  • Save harujoh/3f389ddf4c65a990f9f805faff2b085a to your computer and use it in GitHub Desktop.
Save harujoh/3f389ddf4c65a990f9f805faff2b085a to your computer and use it in GitHub Desktop.
tensorflow/core/platform/ctstring.hの日本語訳
C-API functions TF_StringDecode, TF_StringEncode, and TF_StringEncodedSize are no longer relevant and have been removed;
see core/platform/ctstring.h for string access/modification in C.
●TF_CAPI_EXPORT extern void TF_StringInit(TF_TString *t);
■inline void TF_TString_Init(TF_TString *str);
Initialize a new tstring.
This must be called before using any function below.
新しいtstringを初期化します。
以下の関数を使用する前に必ず呼び出す必要があります。
●TF_CAPI_EXPORT extern void TF_StringDealloc(TF_TString *tstr);
■inline void TF_TString_Dealloc(TF_TString *str);
Deallocate a tstring.
文字列を解放します。
●TF_CAPI_EXPORT extern size_t TF_StringGetSize(const TF_TString *tstr);
■inline size_t TF_TString_GetSize(const TF_TString *str);
Returns the size of the string.
文字列のサイズを返します。
●TF_CAPI_EXPORT extern size_t TF_StringGetCapacity(const TF_TString *str);
■inline size_t TF_TString_GetCapacity(const TF_TString *str);
Returns the capacity of the string buffer.
It should not be considered safe to write in the region between size and capacity---
call Resize or ResizeUninitialized before doing so.
文字列バッファの容量を返す。
サイズと容量の間の領域に書き込むのは安全とは言えません---。
書き込む前に Resize または ResizeUninitialized を呼び出してください。
●TF_CAPI_EXPORT extern TF_TString_Type TF_StringGetType(const TF_TString *str);
■inline TF_TString_Type TF_TString_GetType(const TF_TString *str);
Returns the underlying type of the tstring:
tstringの基礎となる型を返します。
TF_TSTR_SMALL:
Small string optimization; the contents of strings less than 22-bytes are stored in the TF_TString struct.
This avoids any heap allocations.
22バイト以下の文字列の内容をTF_TString構造体に格納します。
これにより、ヒープの割り当てを避けることができます。
TF_TSTR_LARGE:
Heap allocated string.
ヒープ割り当てされた文字列。
TF_TSTR_OFFSET: (currently unused)
An offset defined string.
The string buffer begins at an internally defined little-endian offset from `str';
i.e. GetDataPointer() = str + offset.
This type is useful for memory mapping or reading string tensors directly from file, without the need to deserialize the data.
For security reasons, it is imperative that OFFSET based string tensors are validated before use, or are from a trusted source.
オフセット定義された文字列です。
文字列バッファは、`str' からの内部的に定義されたリトルエンディアンのオフセットで始まります。
すなわち,GetDataPointer() = str + offsetである。
このタイプは,メモリマッピングや,データをデシリアライズすることなく,ファイルから直接文字列テンソルを読み込むのに便利です。
セキュリティ上の理由から、OFFSET ベースの文字列テンソルは、使用前に検証されるか、信頼できるソースからのものであることが必須です。
TF_TSTR_VIEW:
A view into an unowned character string.
所有していない文字列のビュー。
NOTE:
VIEW and OFFSET types are immutable, so any modifcation via Append, AppendN, or GetMutableDataPointer of a VIEW/OFFSET based tstring will result in a conversion to an owned type (SMALL/LARGE).
VIEW および OFFSET 型は不変であるため、VIEW/OFFSET ベースの文字列の Append、AppendN、または GetMutableDataPointer による変更は、所有型(SMALL/LARGE)への変換になります。
●TF_CAPI_EXPORT extern const char *TF_StringGetDataPointer(const TF_TString *tstr);
■inline const char *TF_TString_GetDataPointer(const TF_TString *str);
Returns a const char pointer to the start of the underlying string.
The underlying character buffer may not be null-terminated.
下位の文字列の開始点への const char ポインタを返します。
文字列バッファはヌル終端であってはならない。
●TF_CAPI_EXPORT extern void TF_StringAssignView(TF_TString *dst, const char *src, size_t size);
■inline void TF_TString_AssignView(TF_TString *dst, const char *src, size_t size);
Sets `dst' as a VIEW type to `src'.
`dst' will not take ownership of `src'.
It is the user's responsibility to ensure that the lifetime of `src' exceeds `dst'.
Any mutations to `dst' via Append, AppendN, or GetMutableDataPointer, will result in a copy into an owned SMALL or LARGE type, and will not modify `src'.
srcに対して、`dst' をVIEW型に設定する。
dst' は `src' の所有権を取得しない。
src' の寿命が `dst' よりも長くなるようにするのはユーザの責任である。
Append, AppendN, GetMutableDataPointerによる`dst'への変異は、所有するSMALLまたはLARGE型へのコピーとなり、`src'を変更することはない。
●TF_CAPI_EXPORT extern void TF_StringCopy(TF_TString *dst, const char *src, size_t size);
■inline void TF_TString_Copy(TF_TString *dst, const char *src, size_t size);
Copies `src' to `dst'.
`dst' will be an owned type (SMALL/LARGE).
`src' should not point to memory owned by `dst'.
src' を `dst' にコピーする。
dst' は所有型(SMALL/LARGE)になる。
src' は `dst' が所有するメモリを指してはならない。
(訳注:EXPORTされていない関数にAssignとMoveが存在する。表以下に記載されているの関数を参照
Copy/Move/Assign semantics
| src | dst | complexity
Copy | * | SMALL/LARGE | fixed/O(size)
Assign | SMALL | SMALL | fixed
Assign | OFFSET | VIEW | fixed
Assign | VIEW | VIEW | fixed
Assign | LARGE | LARGE | O(size)
Move | * | same as src | fixed
■inline void TF_TString_Assign(TF_TString *dst, const TF_TString *src);
Assigns a `src' tstring to `dst'. An OFFSET `src' type will yield a `VIEW' `dst'.
LARGE `src' types will be copied to a new buffer.
all other `src' types will incur a fixed cost.
src' の文字列を `dst' に割り当てる。 オフセットされた `src' 型は `VIEW' 型の `dst' を生成する。
大規模な `src' 型は新しいバッファにコピーされる。
他の全ての `src' 型は固定費がかかる。
■inline void TF_TString_Move(TF_TString *dst, TF_TString *src);
Moves a `src' tstring to `dst'.
Moving a LARGE `src' to `dst' will result in a valid but unspecified `src'.
This function incurs a fixed cost for all inputs.
src' 型の文字列を `dst' 型に移動させる。
Largeな`src'を`dst'に移動すると、有効だが指定されていない`src'になる。
この関数は全ての入力に対して固定コストがかかります。
■inline char *TF_TString_Resize(TF_TString *str, size_t new_size, char c);
Resizes `str' to `new_size'.
This function will appropriately grow or shrink the string buffer to fit a `new_size' string.
Grown regions of the string will be initialized with `c'.
str' を `new_size' にリサイズします。
この関数は `new_size' の文字列に合うように文字列バッファを適切に拡大または縮小します。
成長した文字列の領域は `c' で初期化される。
■inline char *TF_TString_ResizeUninitialized(TF_TString *str, size_t new_size);
Similar to TF_TString_Resize, except the newly allocated regions will remain uninitialized.
This is useful if you plan on overwriting the newly grown regions immediately after allocation.
doing so will elide a superfluous initialization of the new buffer.
TF_TString_Resizeと似ていますが、新しく割り当てられた領域は初期化されずに残ります。
これは、割り当て後すぐに新しく成長した領域を上書きしようとする場合に便利です。
このようにすることで、新しいバッファの無駄な初期化を省くことができます。
■inline void TF_TString_Reserve(TF_TString *str, size_t new_cap);
Reserves a string buffer with a capacity of at least `new_cap'.
Reserve will not change the size, or the contents of the existing string.
This is useful if you have a rough idea of `str's upperbound in size, and want to avoid allocations as you append to `str'.
It should not be considered safe to write in the region between size and capacity.
explicitly resize before doing so.
少なくとも `new_cap' の容量を持つ文字列バッファを予約する。
確保してもサイズや既存の文字列の内容は変わりません。
これは、`str'のサイズの上限を大まかに把握していて、`str'に追加する際に割り当てを避けたい場合に便利です。
サイズと容量の間の領域に書き込むことを安全と考えるべきではありません。
書き込む前に明示的にサイズ変更を行ってください。
■inline void TF_TString_ReserveAmortized(TF_TString *str, size_t new_cap);
Similar to TF_TString_Reserve, except that we ensure amortized growth,
i.e. that we grow the capacity by at least a constant factor >1.
TF_TString_Reserve と似ていますが、償却された成長を保証することを除いては、TF_TString_Reserve と似ています。
償却された成長を保証すること以外は、TF_TString_Reserve と同様です。
■inline char *TF_TString_GetMutableDataPointer(TF_TString *str);
Returns a char pointer to a mutable representation of the underlying string.
In the case of VIEW and OFFSET types, `src' is converted to an owned type (SMALL/LARGE).
The underlying character buffer may not be null-terminated.
下位文字列の変更可能な表現への char ポインタを返す。
VIEW型とOFFSET型の場合、`src' は所有型(SMALL/LARGE)に変換される。
文字列バッファはヌル終端であってはならない。
■inline void TF_TString_Append(TF_TString *dst, const TF_TString *src);
■inline void TF_TString_AppendN(TF_TString *dst, const char *src, size_t size);
Appends `src' onto `dst'.
If `dst' is a VIEW or OFFSET type, it will first be converted to an owned LARGE or SMALL type.
`dst' should not point to memory owned by `src'.
src' を `dst' に追加する。
dst' がVIEWまたはOFFSET型の場合、まず所有するLARGEまたはSMALL型に変換される。
dst' は `src' が所有するメモリを指してはならない。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment