Do we have to define #[global_allocator] to use alloc?

In a no-std crate, suppose we are using alloc. Also, say we are not using the global allocator for any data-structure, ie, we are only using a custom allocator, which implements the Allocator trait.
In this case, is it compulsory to define the #[global_allocator] lang-item? Is there a way to avoid it?

Yes, you have to define #[global_allocator] to use liballoc. There is no way to avoid it without making quite drastic changes to liballoc itself to remove every use of a global allocator.

1 Like