Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8597

Other programming languages • Re: Rust-language in Raspberry Pi OS

$
0
0
The Rust program I wrote works very well in Raspberry Pi5. The problem is the size of the files it uses. Those text-files are 6GB and 11GB therefore doesn't fit in the RAM.
I don't know of course, but I'd take a bet that this could be written using less physical memory. The input file of course does not need to be resident, the output file might be written in small chunks - just speculation!
mmap() could perhaps be useful.
A swap-file is needed, but a swap-file is not enable as default in Raspberry Pi OS. That was what I was asking about.
Swap is enabled by default, but its small - 100Mb. The suggestion in your other post simply increases its size.
Note that Linux might use swap for other things than large virtual memory programs - such as moving infrequently accessed (mutable) stuff out of main memory.
See "free -h" for a summary of swap used, also "vmstat" for running details.
When you try to test a program and get errors, all defined errors are automatically fixed, through cargo fix.
Wow! I wish it could fix the bugs in my code :)

If memory is an issue, note that rust programs are very large compared to C programs:

Code:

$ rustc hello.rs$ ls -lh hello-rwxr-xr-x 1 pi pi 12M Apr 29 08:44 hello$ strip hello$ ls -lh hello-rwxr-xr-x 1 pi pi 323K Apr 29 08:44 hello

Code:

$ gcc hello.c -o hello$ ls -lh hello-rwxr-xr-x 1 pi pi 69K Apr 29 08:46 hello$ strip hello$ ls -lh hello-rwxr-xr-x 1 pi pi 66K Apr 29 08:46 hello
I think this is because rust does not use dynamic linking, presumably because the language is still unstable (there is no ISO standard yet). So each and every running rust program has its own private copy of the rust library. The C library OTOH is shared by most of the running programs on the system.
Also comparing the assembler code produced by the two compilers might show another reason for the large sized rust executables.

For fun, even C is huge compared to assembler ...

Code:

$ as hello.s -o hello.o$ ld hello.o -o hello$ ls -lh hello-rwxr-xr-x 1 pi pi 992 Apr 29 08:53 hello$ strip hello$ ls -lh hello-rwxr-xr-x 1 pi pi 384 Apr 29 08:53 hello

Statistics: Posted by jahboater — Mon Apr 29, 2024 7:38 am



Viewing all articles
Browse latest Browse all 8597

Trending Articles