我们可以在 SDL2 中使用 std::fstream 而不是 SDL_RWops 吗?
Can we use std::fstream instead of SDL_RWops in SDL2?
如题,在处理I/O文件时,SDL_RWops
比std::fstream
有什么优势吗?我可以用 std::fstream
代替吗,因为我比较熟悉它?
通过阅读他们的文档,你可以发现 std::fstream
是一个:
Input/output stream class to operate on files.
另一方面,SDL_RWops
是更多的东西:
SDL_RWops is an abstraction over I/O. It provides interfaces to read, write and seek data in a stream, without the caller needing to know where the data is coming from.
For example, a RWops might be fed by a memory buffer, or a file on disk, or a connection to a web server, without any changes to how the caller consumes the data.
相当强的抽象。
那么,您可以使用 std::fstream
代替 SDL_RWops
作为您的文件吗?当然,如果你觉得更有信心,那就去吧。后者是对游戏中任何类型流的有用抽象,因此其优势不仅仅是读取文件。
SDL_RWops may be implemented for many types of data streams. Standard SDL provides SDL_RWFromFile
and SDL_RWFromMem
, while other libraries like physfs 为其支持的许多归档类型提供 RWops 的实现。
RWops 的主要优点是所有 SDL-family 库(SDL_image、SDL_mixer、...)都支持从 RWops 加载,因此您可以轻松地提供自己的特定数据源(例如,您的存档格式,甚至可能是网络资源)给他们。除此之外,它可能适合也可能不适合您的代码,具体取决于您的需要。
如题,在处理I/O文件时,SDL_RWops
比std::fstream
有什么优势吗?我可以用 std::fstream
代替吗,因为我比较熟悉它?
通过阅读他们的文档,你可以发现 std::fstream
是一个:
Input/output stream class to operate on files.
另一方面,SDL_RWops
是更多的东西:
SDL_RWops is an abstraction over I/O. It provides interfaces to read, write and seek data in a stream, without the caller needing to know where the data is coming from.
For example, a RWops might be fed by a memory buffer, or a file on disk, or a connection to a web server, without any changes to how the caller consumes the data.
相当强的抽象。
那么,您可以使用 std::fstream
代替 SDL_RWops
作为您的文件吗?当然,如果你觉得更有信心,那就去吧。后者是对游戏中任何类型流的有用抽象,因此其优势不仅仅是读取文件。
SDL_RWops may be implemented for many types of data streams. Standard SDL provides SDL_RWFromFile
and SDL_RWFromMem
, while other libraries like physfs 为其支持的许多归档类型提供 RWops 的实现。
RWops 的主要优点是所有 SDL-family 库(SDL_image、SDL_mixer、...)都支持从 RWops 加载,因此您可以轻松地提供自己的特定数据源(例如,您的存档格式,甚至可能是网络资源)给他们。除此之外,它可能适合也可能不适合您的代码,具体取决于您的需要。