Keywords: classdesc

Next: BinStream binary Up: pack/unpack Previous: Polymorphism Contents Index

## Packing to a file

Instead of packing to a buffer, and subsequently storing data to a file, you can directly pack to a file by passing the filename and openmode arguments to pack or `xdr_pack`'s constructor. The arguments are identical to that of fopen:

     {
      pack_t checkpoint("foo.ckpt","w");
      checkpoint << bar;
     }

The advantage here is large checkpoints can be written to disk without intermediate buffering in memory. The file is closed when the `pack_t` object is destroyed.