...

/

Box<T>

Box<T>

In this lesson, you will learn about Smart Pointer `Box<T>`.

What is Box<T>

Just like malloc in C, Box<T> is a pointer that is used to allocate variables on the heap. The pointer remains on the stack while pointing to the data in the heap. Box is useful when you need a value that cannot fit in the stack and it needs to grow.

Allocation

You can allocate to the heap using new(). Here’s an example:

let p = Box::new(15);

We are creating a Boxed pointer that ...

Access this course and 1400+ top-rated courses and projects.