{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreied22oeo2zphkfmmibpx74joqqwqiismhqhjass2atyklndqn3lx4",
"uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mkf4qrhvga22"
},
"path": "/t/on-usage-of-custom-allocators/24204#post_1",
"publishedAt": "2026-04-26T06:38:26.000Z",
"site": "https://internals.rust-lang.org",
"tags": [
"See here"
],
"textContent": "Currently, on unstable, Vec (and other types such as Rc, Box etc) is being enhanced with a generic allocator parameter, wiht a default of Global.\n\n`struct Vec<T, A:Allocator=Global>;`\n\nI have been experimenting with custom allocators, and have found it much more convenient to instead have a new struct which doesn't have a default and then define Vec with a type alias, like this:\n\n\n struct VecA<T, A: Allocator>;\n type Vec<T> = VecA<T, Global>;\n\n\n( See here for details )\n\nThe advantage is that when used with any allocator that implements Default (and not just Global), methods such as new, with_capacity and traits such as Default, From are still available. This reduces source edits to change to an allocator other than Global considerably. A type defined as `Vec<T> = VecA<T,Local>` is now almost identical to a normal Vec except it is allocated differently. The only exception is a different `vec!` macro is needed, `veca!` rather than `vec!`.\n\nAs far as I know this does not cause compatibility issues with stable Vec, Box etc, so I think it could be considered for the standard library as a better way to enhance Vec, Box, Rc, String etc. to support custom allocators.",
"title": "On usage of Custom Allocators"
}