我发现了古老的,巨大的开源代码,该代码对存储在磁盘文件中的二进制数据进行一些计算,输出也保存为二进制文件.
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 *
发布评论