The preceding project defined a global variable, but it did not carry out memory allocation. Even in kernel modules, it is possible to allocate memory, as shown in the allocating project.
To run this project, open the allocating folder and type in ./bd. Then, type the following four commands:
sudo insmod allocating.ko
lsmod | grep -w allocating
sudo rmmod allocating
dmesg --color=always | tail
These commands have a behavior quite similar to the corresponding commands for the preceding project, but the last one will print a line that, after the timestamp, will contain the following text:
allocating: Unloaded 1001 abcd 500000
Let's examine the source code of this project and see its differences compared with the boilerplate source code. The lib.rs file contains the following additional lines:
extern crate alloc;
use crate::alloc::string::String;
use crate::alloc::vec::Vec;
The first line explicitly declares that a memory allocator is needed. Otherwise, as the standard...