Skip to content

Commit 99c926e

Browse files
committed
Document Pool's unusual requirements.
1 parent fbbdc8b commit 99c926e

1 file changed

Lines changed: 23 additions & 8 deletions

File tree

wgpu-remote/src/pool/mod.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
/*! A heap allocator for shared memory blocks.
22
3-
This module defines the [`Pool`] type, which suballocates blocks from some
4-
large underlying contiguous block of memory. This crate uses a [`Sender`]
5-
implementation to create large blocks of memory shared between client and server,
6-
and then uses [`Pool`] to dice those large blocks up into individual buffers
7-
for mapping wgpu [`Buffer`]s, large buffer writes, and so on.
8-
9-
This allocator uses the [Binary Buddy][bb] algorithm to place allocated blocks
10-
and coalesce free ranges.
3+
This module defines the [`Pool`] type, which suballocates blocks from
4+
some large underlying contiguous block of memory. It uses the [Binary
5+
Buddy][bb] algorithm to place allocated blocks and coalesce free
6+
ranges.
7+
8+
This crate uses a [`Sender`] implementation to create large blocks of
9+
memory shared between client and server, and then uses [`Pool`] to
10+
subdivide those large blocks up into individual buffers for mapping
11+
wgpu [`Buffer`]s, large buffer writes, and so on.
12+
13+
## Why do we need another allocator?
14+
15+
There are plenty of heap allocators out there, but this crate has the
16+
unusual constraint that the memory being managed may be writable by an
17+
untrusted party. This means that we can't use free space to hold
18+
memory management metadata like freelists, page headers, and so on.
19+
All our metadata must live outside the underlying blocks of shared
20+
memory.
21+
22+
One nice consequence of keeping the metadata separate is that the
23+
allocator uses only one piece of unsafe code, for constructing the
24+
sub-`Block` of the larger block we're dicing up. The rest of this
25+
allocator simply operates on ordinary safe Rust types.
1126
1227
[`Sender`]: crate::transport::Sender
1328
[`Buffer`]: https://docs.rs/wgpu/latest/wgpu/struct.Buffer.html

0 commit comments

Comments
 (0)