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

}
相关推荐
咸甜适中8 小时前
rust语言学习笔记Trait(八)Iterator(迭代器)
笔记·学习·rust
zoomdong13 小时前
@utoo/pack: 基于 Turbopack 的下一代 Rust 构建工具
webpack·rust·开源
数据法师1 天前
MotrixNext:接棒经典 Motrix,用 Tauri 2+Rust 重构的下一代开源下载神器
重构·rust·开源
卡卡军1 天前
agmd 1.0 重磅升级——Rust 重写,性能起飞
javascript·rust
codealy2 天前
Rust 核心理论: 高并发与异步(三)
算法·rust
咸甜适中2 天前
rust语言学习笔记Trait(七) IntoIterator(由集合创建迭代器)
笔记·学习·rust
本地化文档2 天前
rust-style-guide-l10n
rust·github·gitcode
樱桃花下的小猫2 天前
腐蚀Rust-EAC 及官方验证关闭教程
服务器·rust·云鸢互联·零门槛一键开服·腐蚀rust服务器
咸甜适中2 天前
rust语言学习笔记Trait(六) FromIterator(由迭代器创建集合)
笔记·学习·rust