如何在Windows上将BYTE数组映射为FILE *

编程入门 行业动态 更新时间:2024-10-28 21:18:45
本文介绍了如何在Windows上将BYTE数组映射为FILE *的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我发现了古老的,巨大的开源代码,该代码对存储在磁盘文件中的二进制数据进行一些计算,输出也保存为二进制文件.

I found old, huge open source code which performs some computations on binary data stored in file on disk, output is also saved as binary file.

我想使用一种根方法,简化签名:

There is one root method which I would like to use, simplified signature:

int magic(FILE* input, FILE* output);

问题是我将输入数据存储在进程内存中,并且我希望输出也作为进程内存.代码是如此之大,以至于我无法在合理的时间内重写它.

The problem is that I store input data in process memory and I would like to have output also as memory in process. Code is so big that I'm not able to rewrite it in resonable time.

此API迫使我在每次调用magic()时都要进行两个巨大的I/O.

This API forces me to make two huge I/O on every call to magic().

在Windows上是否可以使用C/C ++机制将BYTE数组映射为FILE*?

Is there any possibility to map BYTE array as FILE* on Windows using C/C++ mechanisms?

推荐答案

似乎您需要fmemopen的功能:

man7/linux/man-pages /man3/fmemopen.3.html

哪个占据一个内存区域并返回一个文件描述符. 不幸的是,这是POSIX函数,在Windows中没有等效的函数.内存映射文件可能不是您想要的,因为它们会获取现有文件并将其映射到内存区域,而不是像fmemopen那样.您唯一的选择是要么在Windows上的mingw中使用fmemopen(不知道是否可以这样做),要么推出自己的fopen,fwrite等版本.

Which takes a memory region and returns a file descriptor. Unfortunately, this is a POSIX function that does not have an equivalent in Windows. Memory mapped files are probably not what you want, as they take an existing file and map it to a memory region, not the other way around as with fmemopen. The only options you have are to either use fmemopen with mingw on Windows (don't know if you can do this) or roll out your own versions of fopen, fwrite and so on.

更多推荐

如何在Windows上将BYTE数组映射为FILE *

本文发布于:2023-10-07 16:54:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469955.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   上将   如何在   FILE   Windows

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!