Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#ActualNypyren

Posted 07 March 2013 - 03:36 PM

Generally what I do for buffering is use something like C#'s BinaryWriter and a MemoryStream.

MemoryStream is a wrapper around a byte array which allows the array to dynamically grow, and also keeps a Position pointer, which tracks where to read/write next.

BinaryWriter is a fairly simple class that just converts values to bytes, copies them to the underlying stream, and increments the stream's position pointer as it goes.

After you're done writing to the MemoryStream, you just grab its internal byte array and dump the entire thing into your file in a single call.


It's trivial to do this in C++ - you can either use existing stream classes which support most of this, or if you want to use a C interface, it's trivial to write it from scratch with minimal effort (it's a hundred lines of code or less - basically a few dozen functions with 1-3 lines apiece).

#2Nypyren

Posted 07 March 2013 - 03:36 PM

Generally what I do for buffering is use something like C#'s BinaryWriter and a MemoryStream.

MemoryStream is a wrapper around a byte array which allows the array to dynamically grow, and also keeps a Position pointer, which tracks where to read/write next.

BinaryWriter is a fairly simple class that just converts values to bytes, copies them to the underlying stream, and increments the stream's position pointer as it goes.

After you're done writing to the MemoryStream, you just grab its internal byte array and dump the entire thing into your file in a single call.


It's trivial to do this in C++ - you can either use existing stream classes which support most of this. If you want to use a C interface, it's trivial to write it from scratch with minimal effort (it's a hundred lines of code or less - basically a few dozen functions with 1-3 lines apiece).

#1Nypyren

Posted 07 March 2013 - 03:35 PM

Generally what I do for buffering is use something like C#'s BinaryWriter and a MemoryStream.

MemoryStream is a wrapper around a byte array which allows the array to dynamically grow, and also keeps a Position pointer, which tracks where to read/write next.

BinaryWriter is a fairly simple class that just converts values to bytes, copies them to the underlying stream, and increments the stream's position pointer as it goes.

After you're done writing to the MemoryStream, you just grab its internal byte array and dump the entire thing into your file in a single call.


It's trivial to do this in C++ - you can either use existing stream classes which support most of this, or write your own classes to do it with minimal effort (it's a hundred lines of code or less - basically a few dozen functions with 1-3 lines apiece).

PARTNERS