Skip to main content

use_global_allocator

Function use_global_allocator 

Source
pub fn use_global_allocator() -> bool
Expand description

Route OpenSSL memory allocations to the Rust global allocator.

OpenSSL allocates with the C runtime malloc by default. After this call it allocates through std::alloc, so an application that registers a #[global_allocator] (for example mimalloc) uses it for tls buffers and handshake state as well.

The setting is process wide and OpenSSL accepts it only before its first allocation, call this at the start of main before any other OpenSSL use. Returns false if OpenSSL has already allocated memory or the linked library does not support custom allocators (OpenSSL older than 1.1.0, LibreSSL, BoringSSL, aws-lc), OpenSSL keeps using malloc in that case.