<commit_before># Aligned Allocations for Rust

| Linux / OS X Build |
| ------------------ |
| [![Build Status](https://travis-ci.org/jonas-schievink/aligned_alloc.rs.svg?branch=master)](https://travis-ci.org/jonas-schievink/aligned_alloc.rs) |

This crate provides cross-platform primitives for requesting specifically
aligned allocations. It is **not** meant to be used as a general allocator API
like `alloc::heap`, but can be used for infrequent large allocations that have a
specific alignment requirement.

For example, certain arena allocators can find the arena in which an object was
allocated by masking the address bits if the arena is aligned to its size.

# Usage

As usual, in your `Cargo.toml`:
```toml
[dependencies]
aligned_alloc = "0.1"
```

And in your `lib.rs` or `bin.rs`:
```rust
extern crate aligned_alloc;<commit_msg>Update Readme with Appveyor badge and impl details<commit_after># Aligned Allocations for Rust

| Linux / OS X | Windows |
| :----------: | :-----: |
| [![Build Status](https://travis-ci.org/jonas-schievink/aligned_alloc.rs.svg?branch=master)](https://travis-ci.org/jonas-schievink/aligned_alloc.rs) | [![Build status](https://ci.appveyor.com/api/projects/status/87oi2nolh91715px/branch/master?svg=true)](https://ci.appveyor.com/project/jonas-schievink/aligned-alloc-rs/branch/master) |

This crate provides cross-platform primitives for requesting specifically
aligned allocations. It is **not** meant to be used as a general allocator API
like `alloc::heap`, but can be used for infrequent large allocations that have a
specific alignment requirement.

For example, certain arena allocators can find the arena in which an object was
allocated by masking the address bits if the arena is aligned to its size.

On Unix, this crate makes use of the `posix_memalign` function. On Windows, it's
a little more complicated: We use `VirtualAlloc` to reserve a chunk of address
space large enough for the allocation plus alignment (no memory is actually
allocated), then calculate an aligned address inside this reserved space, undo
the reservation with `VirtualFree` (the extra bit of reserved memory for the
alignment won't get wasted), and `VirtualAlloc` again, this time passing the aligned pointer and
actually allocating the memory instead of just reserving address space.

# Usage

As usual, in your `Cargo.toml`:
```toml
[dependencies]
aligned_alloc = "0.1"
```

And in your `lib.rs` or `bin.rs`:
```rust
extern crate aligned_alloc;
{'fraction_non_alphanumeric': 0.10751818916734034, 'fraction_numerical': 0.004850444624090542, 'mean_word_length': 4.689655172413793, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1231262', 'n_tokens_mistral': 740, 'n_tokens_neox': 703, 'n_words': 287}