rust read 100G large file

rust 复制代码
/**

 * Main function that demonstrates memory mapping a large file and accessing its contents.

 *

 * This function:

 * 1. Opens a large virtual disk file (ext4.vhdx)

 * 2. Creates a memory mapping of the file

 * 3. Accesses the mapped content

 * 4. Prints the memory address of the content and its length

 *

 * Returns:

 *   Result<(), Box<dyn std::error::Error>> - Ok on success, or an error boxed as a trait object

 */

fn main() -> Result<(), Box<dyn std::error::Error>> {

    use std::fs::File;

    use doe::memory_address;

    use memmap2::Mmap;

   

    // Open the virtual disk file in read-only mode

    let file = File::open("D:/arch_linux/ext4.vhdx")?;

   

    // Create a memory map of the entire file (unsafe due to potential undefined behavior)

    let mmap = unsafe { Mmap::map(&file)? };

  


    // Get a slice reference to the entire mapped memory

    let content = &mmap[..];

 

    // Print the memory address and length of the mapped content

    println!("memory_address:{:?}", memory_address!(content));

    println!("len:{}", content.len());

   

    Ok(())

}
相关推荐
蚂蚁背大象17 小时前
Rust 所有权系统是为了解决什么问题
后端·rust
布列瑟农的星空17 小时前
前端都能看懂的rust入门教程(五)—— 所有权
rust
Java水解2 天前
Rust嵌入式开发实战——从ARM裸机编程到RTOS应用
后端·rust
Pomelo_刘金2 天前
Rust:所有权系统
rust
Ranger09292 天前
鸿蒙开发新范式:Gpui
rust·harmonyos
DongLi015 天前
rustlings 学习笔记 -- exercises/05_vecs
rust
番茄灭世神5 天前
Rust学习笔记第2篇
rust·编程语言
shimly1234566 天前
(done) 速通 rustlings(20) 错误处理1 --- 不涉及Traits
rust
shimly1234566 天前
(done) 速通 rustlings(19) Option
rust
@atweiwei6 天前
rust所有权机制详解
开发语言·数据结构·后端·rust·内存·所有权