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

}
相关推荐
遇码几秒前
给 Rust 桌面应用做双击安装包:Windows NSIS setup.exe + macOS DMG 的完整做法
人工智能·windows·ai·rust·大模型
GitCode官方3 小时前
本期精选 Rust 开源项目推荐
开发语言·rust·开源·g-star·atomgit
nezuko356 小时前
用 AI 把代码改写成 Rust 之后,怎么证明它没改坏?我做了个开源工具
rust
爆米花byh1 天前
在RockyLinux9环境下安装Rust1.100.0环境
linux·rust
hai3152475431 天前
阶乘分层关系模型存储文本与表格
数据结构·算法·rust·排序算法·线性回归
Shota Kishi1 天前
Solana Stream SDK 的 UDP Shred 接收:data-only 与 recover 两种模式的取舍与实测
rust·区块链·solana
tomatohug1 天前
Tauri v2 实战:做一个贴在任何输入框上的提示词优化助手
rust
Zenova EdgeOS1 天前
Rust 数据库实战:工业边缘场景下的 sqlx
数据库·oracle·rust·边缘计算·工业网关
用户46043852250862 天前
关于paimon- rust的学习 --- Table(一)
大数据·rust
Kapaseker2 天前
快 18 倍?Laravel Rust 才是 Laravel 的未来
rust