简体   繁体   English

相当于 MSVC 的 open_memstream

[英]Equivalent of open_memstream for MSVC

I am using open_memstream in a library of mine, but I would like to port this library to MSVC.我在我的库中使用open_memstream ,但我想将此库移植到 MSVC。 It seems there are no equivalent function available, but is there something similar enough?似乎没有可用的等效功能,但是有足够相似的功能吗?

What open_memstream does is it takes a char** destination and size and returns a FILE* which you many write to, the data is stored in a dynamically allocated buffer (accessible from the char** argument). open_memstream所做的是它接受一个 char** 目标和大小并返回一个 FILE*,您可以将其写入许多文件,数据存储在动态分配的缓冲区中(可从 char** 参数访问)。 When closing the FILE the char** contains the data that was written to the stream.关闭 FILE 时,char** 包含写入流的数据。 This makes an easy way to construct large and complex string streams.这为构造大型复杂字符串流提供了一种简单的方法。

While it is possible to both read and seek from the memstream I only write to it.虽然可以从 memstream 中读取和查找,但我只向它写入。

Is there a way to open a similar memory FILE stream in MSVC?有没有办法在 MSVC 中打开类似的内存文件流? Also, this is pure C, no C++.此外,这是纯 C,没有 C++。

A similar function on Windows would be CreateStreamOnHGlobal(). Windows 上的类似函数是 CreateStreamOnHGlobal()。 That however works with the IStream COM interface, it isn't a drop-in replacement for FILE.然而,它适用于 IStream COM 接口,它不是 FILE 的直接替代品。 You might want to take a peek at the Cygwin source code to see what they did.您可能想看一看 Cygwin 源代码,看看它们做了什么。

https://github.com/Snaipe/fmem is a wrapper for different platform/version specific equivalents of open_memstream https://github.com/Snaipe/fmem是 open_memstream 的不同平台/版本特定等价物的包装器

It tries in sequence the following implementations:它依次尝试以下实现:

  • open_memstream. open_memstream。
  • fopencookie, with growing dynamic buffer. fopencookie,具有不断增长的动态缓冲区。
  • funopen, with growing dynamic buffer. funopen,具有不断增长的动态缓冲区。
  • WinAPI temporary memory-backed file. WinAPI 临时内存支持文件。

When no other mean is available, fmem falls back to tmpfile()当没有其他方法可用时,fmem 回退到 tmpfile()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM