Skip to content

Commit 714f969

Browse files
committed
fix translation & change code block comment
1 parent 8ea15d1 commit 714f969

File tree

2 files changed

+40
-20
lines changed

2 files changed

+40
-20
lines changed

1.6/ja/book/custom-allocators.md

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<!-- allocate and deallocate memory. The standard library is not compiled assuming -->
2222
<!-- either one, and the compiler will decide which allocator is in use at -->
2323
<!-- compile-time depending on the type of output artifact being produced. -->
24-
現在コンパイラは `alloc_system``alloc_jemalloc` (いくつかのターゲットにはありません)という2つの既定のアロケータを提供しています。これらのアロケータは単に普通のRustのクレートで、メモリの割り当てと解放の手続きを実装しています。標準ライブラリはどちらか一方を前提としてコンパイルされているわけではありません。コンパイラは生成する成果物の種類に応じてどちらのアロケータを使用するかをコンパイル時に決定します。
24+
現在コンパイラは `alloc_system``alloc_jemalloc` (jemallocのないターゲットもあります)という2つの既定のアロケータを提供しています。これらのアロケータは単に普通のRustのクレートで、メモリの割り当てと解放の手続きを実装しています。標準ライブラリはどちらか一方を前提としてコンパイルされているわけではありません。コンパイラは生成する成果物の種類に応じてどちらのアロケータを使用するかをコンパイル時に決定します。
2525

2626
<!-- Binaries generated by the compiler will use `alloc_jemalloc` by default (where -->
2727
<!-- available). In this situation the compiler "controls the world" in the sense of -->
@@ -45,13 +45,12 @@
4545
コンパイラによる既定の選択はほとんどの場合うまく動きますが、しばしば多少の調整が必要になることがあります。コンパイラのアロケータ選択を上書きするには、単に希望のアロケータとリンクするだけです。
4646

4747
```rust,no_run
48-
4948
#![feature(alloc_system)]
5049
5150
extern crate alloc_system;
5251
5352
fn main() {
54-
let a = Box::new(4); // allocates from the system allocator
53+
# // let a = Box::new(4); // allocates from the system allocator
5554
let a = Box::new(4); // システムアロケータからのメモリ割り当て
5655
println!("{}", a);
5756
}
@@ -69,7 +68,7 @@ fn main() {
6968
extern crate alloc_jemalloc;
7069
7170
pub fn foo() {
72-
let a = Box::new(4); // allocates from jemalloc
71+
# // let a = Box::new(4); // allocates from jemalloc
7372
let a = Box::new(4); // jemallocからのメモリ割り当て
7473
println!("{}", a);
7574
}
@@ -89,34 +88,52 @@ pub fn foo() {
8988
```rust,no_run
9089
# // only needed for rustdoc --test down below
9190
# #![feature(lang_items)]
92-
// The compiler needs to be instructed that this crate is an allocator in order
93-
// to realize that when this is linked in another allocator like jemalloc should
94-
// not be linked in
91+
# //// The compiler needs to be instructed that this crate is an allocator in order
92+
# //// to realize that when this is linked in another allocator like jemalloc should
93+
# //// not be linked in
9594
// コンパイラがリンク時に他のアロケータ(例えばjemalloc)とリンクしてしまうことを防ぐため、
9695
// このクレートがアロケータであることを示す必要があります。
9796
#![feature(allocator)]
9897
#![allocator]
9998
100-
// Allocators are not allowed to depend on the standard library which in turn
101-
// requires an allocator in order to avoid circular dependencies. This crate,
102-
// however, can use all of libcore.
99+
# //// Allocators are not allowed to depend on the standard library which in turn
100+
# //// requires an allocator in order to avoid circular dependencies. This crate,
101+
# //// however, can use all of libcore.
103102
// 循環依存を避けるため、アロケータはアロケータを使う標準ライブラリに依存してはいけません。
104103
// しかしlibcoreについては全ての機能を使用できます。
105104
#![no_std]
106105
107-
// Let's give a unique name to our custom allocator
106+
# //// Let's give a unique name to our custom allocator
108107
// カスタムアロケータに固有の名前を付けてください。
109108
#![crate_name = "my_allocator"]
110109
#![crate_type = "rlib"]
111110
112-
// Our system allocator will use the in-tree libc crate for FFI bindings. Note
113-
// that currently the external (crates.io) libc cannot be used because it links
114-
// to the standard library (e.g. `#![no_std]` isn't stable yet), so that's why
115-
// this specifically requires the in-tree version.
116-
// この独自アロケータはFFIバインディングのためにin-treeのlibcクレートを使います。
111+
# //// Our system allocator will use the in-tree libc crate for FFI bindings. Note
112+
# //// that currently the external (crates.io) libc cannot be used because it links
113+
# //// to the standard library (e.g. `#![no_std]` isn't stable yet), so that's why
114+
# //// this specifically requires the in-tree version.
115+
// この独自アロケータはFFIバインディングのためにRustコンパイラのソースコードに
116+
// 同梱されているlibcクレートを使います。
117117
// 注記: 現在の外部libc(crate.ioのもの)は標準ライブラリとリンクしているため使用できません
118-
// ( `#![no_std]` がまだstableではないためです)。そのため特別にin-treeのlibcが必要になります
118+
// ( `#![no_std]` がまだstableではないためです)。そのため特別に同梱版のlibcが必要になります
119119
#![feature(libc)]
120+
extern crate libc;
121+
122+
# //// Listed below are the five allocation functions currently required by custom
123+
# //// allocators. Their signatures and symbol names are not currently typechecked
124+
# //// by the compiler, but this is a future extension and are required to match
125+
# //// what is found below.
126+
# ////
127+
# //// Note that the standard `malloc` and `realloc` functions do not provide a way
128+
# //// to communicate alignment so this implementation would need to be improved
129+
# //// with respect to alignment in that aspect.
130+
// 今のところ、カスタムアロケータには以下の5つのメモリ割り当て関数が必要です。
131+
// コンパイラは現時点では関数のシグネチャとシンボル名の型検査を行いません。
132+
// しかし、将来的には以下の型に一致する必要があります。
133+
//
134+
// 注記: 標準の `malloc` と `realloc` 関数へはアラインメントについての情報を
135+
// 渡すことができません。そのためアラインメントを考慮するためにはこの実装は
136+
// 改良の必要があります。
120137
121138
#[no_mangle]
122139
pub extern fn __rust_allocate(size: usize, _align: usize) -> *mut u8 {
@@ -139,7 +156,7 @@ pub extern fn __rust_reallocate(ptr: *mut u8, _old_size: usize, size: usize,
139156
#[no_mangle]
140157
pub extern fn __rust_reallocate_inplace(_ptr: *mut u8, old_size: usize,
141158
_size: usize, _align: usize) -> usize {
142-
old_size // this api is not supported by libc
159+
# // old_size // this api is not supported by libc
143160
old_size // このAPIはlibcではサポートされていません。
144161
}
145162
@@ -164,7 +181,7 @@ pub extern fn __rust_usable_size(size: usize, _align: usize) -> usize {
164181
extern crate my_allocator;
165182
166183
fn main() {
167-
let a = Box::new(8); // allocates memory via our custom allocator crate
184+
# // let a = Box::new(8); // allocates memory via our custom allocator crate
168185
let a = Box::new(8); // カスタムアロケータによるメモリ割り当て
169186
println!("{}", a);
170187
}
@@ -188,4 +205,4 @@ fn main() {
188205
<!-- depend on a crate which needs an allocator (e.g. circular dependencies are not -->
189206
<!-- allowed). This basically means that allocators must restrict themselves to -->
190207
<!-- libcore currently. -->
191-
* アロケータを使うコードは `#![needs_allocator]` でタグ付けされます(例えば現時点での `liballoc` クレート)。また、 `#[allocator]` がついたクレートはアロケータを使うクレートに依存することが出来ません(循環依存は許されていません)。このためアロケータは原則としてlibcoreにしか依存しないようにする必要があります。
208+
* アロケータを使うコードは `#![needs_allocator]` でタグ付けされます(例えば現時点での `liballoc` クレート)。また、 `#[allocator]` がついたクレートはアロケータを使うクレートに直接的にも間接的にも依存することが出来ません(例えば、循環依存は許されていません)。このためアロケータは原則としてlibcoreにしか依存しないようにする必要があります。

TranslationTable.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
| English | 日本語
1212
|:----------------------|:------
13+
| alignment | アラインメント
1314
| allocator | アロケータ
1415
| application | アプリケーション
1516
| associated - | 関連-
@@ -41,8 +42,10 @@
4142
| owner | 所有者
4243
| ownership | 所有権
4344
| return | 返す
45+
| signature | シグネチャ
4446
| struct | 構造体
4547
| structure | ストラクチャ
48+
| symbol | シンボル
4649
| system | システム
4750
| trait | トレイト
4851
| unsized type | サイズ不定型

0 commit comments

Comments
 (0)