Reputation: 629
I'm trying to use Arc in my code, but as i read the document, there is 2 places Arc is defined: std crate and alloc crate. So, what is the different between alloc::sync::Arc and std::sync::Arc?
Upvotes: 1
Views: 1316
Reputation: 796
The core
and alloc
crates exist if you’re writing a kernel or some other low-level piece of software and still need to use those APIs. Unless you’re writing something that is low-level enough to declare #![no_std]
, there’s no advantage to using alloc
over std
since the structures are identical.
Upvotes: 0
Reputation: 2907
From the alloc
crate documentation:
This library provides smart pointers and collections for managing heap-allocated values.
This library, like libcore, normally doesn’t need to be used directly since its contents are re-exported in the
std
crate. Crates that use the#![no_std]
attribute however will typically not depend on std, so they’d use this crate instead.
So there's no difference between std::sync::Arc
and alloc::sync::Arc
.
alloc
also provides Box
, Vec
, String
, the collections
module, and basically anything in the standard library that requires allocations (hence alloc
) but not an underlying OS (filesystem, networking, etc). alloc
is there if you want to write bare-metal (unhosted) software that still gets to use the nice standard library data structures.
Upvotes: 3