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

}
相关推荐
doiito7 小时前
【Agent Harness】Gliding Horse v0.1.4.preview 发布:时间感知、闭环审计与智能增强
ai·rust·架构设计·系统设计·ai agent
独孤留白8 小时前
从C到Rust:堆内存,数据如何逃逸栈的约束?
rust
doiito(Do It Together)9 小时前
【安全,架构】RustyVault 项目深度分析报告以及和HashiCorp Vault的差异
微服务·架构·rust
问窗9 小时前
Rust实现Windows本地搜索工具
windows·搜索引擎·rust
程序员爱钓鱼11 小时前
Rust 变量与不可变性:为什么默认不能修改变量?
前端·后端·rust
第一程序员21 小时前
Rust Agent 子进程执行:Command 之前,先定义输入和超时
python·rust·github
IT笔记1 天前
【Rust】Rust Match 模式匹配详解
java·开发语言·rust
取地址符1 天前
Rust学习笔记(基于Rustlings)(2):数据结构与集合
笔记·学习·rust
取地址符1 天前
Rust语法学习 (基于Rustlings)(1):基础语法
经验分享·笔记·学习·rust