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(())

}
相关推荐
Pomelo_刘金10 小时前
用 DDD 把「闹钟」需求一点点捏出来
架构·rust·领域驱动设计
Pomelo_刘金10 小时前
Clean Architecture 整洁架构:借一只闹钟讲明白「整洁架构」的来龙去脉
后端·架构·rust
a cool fish(无名)20 小时前
rust-方法语法
开发语言·后端·rust
a cool fish(无名)1 天前
rust-参考与借用
java·前端·rust
叶 落2 天前
[Rust 基础课程]猜数字游戏-获取用户输入并打印
rust·rust基础
RustFS2 天前
RustFS 如何修改默认密码?
rust
景天科技苑2 天前
【Rust线程池】如何构建Rust线程池、Rayon线程池用法详细解析
开发语言·后端·rust·线程池·rayon·rust线程池·rayon线程池
该用户已不存在3 天前
Zig想要取代Go和Rust,它有资格吗
前端·后端·rust
用户1774125612443 天前
不懂装懂的AI,折了程序员的阳寿
rust
量子位4 天前
vivo自研蓝河操作系统内核开源!Rust开发新机遇来了
rust·ai编程