# Memory Operations

> StringZilla for Rust

`use stringzilla::UnifiedAllocator;`

## UnifiedAllocator

Memory the host and the devices of one capability group both address, for the columns and the outputs of their engines.

```rust
pub struct UnifiedAllocator<'stream>
```

It is the C library's `sz_allocator_init_unified_best` behind the standard
`Allocator`, so `Vec::new_in`, a [`Strings`](https://www.unum.cloud/docs/stringzilla/rust/types.md#Strings) and every other
allocator-aware collection places its contents there. Every block lands on the device of the
stream it borrows, the host heap for a CPU stream, and a block aligned less strictly than its
layout asks is refused.

Examples: ```
use stringzilla::{Capabilities, LevenshteinEngine, LevenshteinSymbol, Stream, Strings, StringsView, UnifiedAllocator};

let cpu = Stream::default(Capabilities::cpu_enabled());
let stream = Stream::new(Capabilities::cuda_enabled(0)?, 0)?;
let unified = UnifiedAllocator::new(&#x26;stream);
// The host gathers the slices, which a GPU cannot read, into memory the GPU reaches.
let candidates = Strings::copy_in(StringsView::from_slices(&#x26;["sitting", "kitten"]), unified, &#x26;cpu)?;
let mut distances = Vec::new_in(unified);
distances.resize(2, 0usize);

let mut engine = LevenshteinEngine::new(&#x26;["kitten"], LevenshteinSymbol::Bytes, &#x26;stream)?;
stream.scope(|scope| engine.distances(scope, candidates.view(), None, &#x26;mut distances, 2))?;
assert_eq!(distances[..], [3, 0]);
```

Implements: `Clone`, `Copy`, `Debug`, `Allocator`

## new

Unified memory on the device of `stream`, the host heap for a CPU stream.

```rust
pub const fn new(stream: &'stream Stream) -> Self
```

## capabilities

The capabilities whose memory every block comes from.

```rust
pub fn capabilities(&self) -> Capabilities
```

