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

}
相关推荐
滕州市燕猫虎计算机科技工作室个体工商户6 小时前
《Rust程序设计》学习笔记八:结构体
笔记·学习·rust·rust程序设计
Amos_Web16 小时前
Rspack 源码解析(二十一):Cacheable 与 Storage 如何持久化编译结果
前端·rust·前端框架
可乐ea17 小时前
2000 个智能体把 Agent 重写成 Rust:编排流水线拆解
开发语言·后端·rust·多智能体协作·ai编程助手·智能体编排·rust重写
Amos_Web17 小时前
Rspack 源码解析(二十二):ExternalsPlugin 如何在 Factorize 阶段换掉整个模块
前端·rust·前端框架
梦醒沉醉19 小时前
7、Rust参考手册——属性
rust
滕州市燕猫虎计算机科技工作室个体工商户1 天前
《Rust程序设计》学习笔记六:错误处理
rust·学习笔记·rust程序设计·rust学习笔记
达子6661 天前
RUST 图解 第 3 章:通用编程概念(Common Programming Concepts)
开发语言·算法·rust
对象存储与RustFS2 天前
HelixDB 上手:Agent 记忆新方案,基于 RustFS 对象存储,附完整 docker-compose 部署示例
后端·rust·开源
Amos_Web2 天前
Rspack 源码解析(二十):Typed Hook 系统如何靠宏生成
前端·rust·前端框架
Source.Liu2 天前
【A11】拆分前端,实现多页面方案
前端·rust