Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

One way to ensure that Box::new() actually allocates memory on the heap is to check the address of the value returned by Box::into_raw(). If the address is within a certain range (which varies depending on the platform), then it is very likely that the memory was allocated on the heap. Another way is to use a memory profiler or a tool like Valgrind to verify that memory is being allocated on the heap. Additionally, the Rust documentation for Box::new() states that it "allocates memory with the global allocator" which is typically the heap, so it is generally safe to assume that memory is being allocated on the heap.