# vtkWriter to memory

**URL:** https://discourse.vtk.org/t/vtkwriter-to-memory/8087
**Category:** Support
**Created:** [March 19, 2022, 3:39pm UTC](https://discourse.vtk.org/t/vtkwriter-to-memory/8087 "2022-03-19T15:39:29Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![whophil](https://discourse.vtk.org/user_avatar/discourse.vtk.org/whophil/32/2857_2.png) [@whophil](https://discourse.vtk.org/u/whophil)
#### Post date: [March 19, 2022, 3:39pm UTC](https://discourse.vtk.org/t/vtkwriter-to-memory/8087/1 "2022-03-19T15:39:29Z")

</div>

Occasionally I want to use a `vtkWriter` to write to memory instead of disk. The docs offer this teaser:

> [vtkWriter](https://vtk.org/doc/nightly/html/classvtkWriter.html) is an abstract class for mapper objects that write their data to disk (or into a communications port)

Is the ability to write to memory or a communications port something which must be implemented by the subclass, or is there a way to make _any_ vtkWriter write to memory?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [March 21, 2022, 3:37am UTC](https://discourse.vtk.org/t/vtkwriter-to-memory/8087/2 "2022-03-21T03:37:56Z")

</div>

AFAIK, this is something each writer must implement as most operate on paths. Note that some writers handle formats that write directories of files rather than single files, so these are much harder to support (though `vtkArchiver` could be used to do this, useful subclasses are not generally available because they require an external dependency).

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [March 21, 2022, 6:40am UTC](https://discourse.vtk.org/t/vtkwriter-to-memory/8087/3 "2022-03-21T06:40:37Z")

</div>

Hi @whophil

vtkDataWriter::WriteToOutputString lets you do that.

Best,

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [March 21, 2022, 6:53am UTC](https://discourse.vtk.org/t/vtkwriter-to-memory/8087/4 "2022-03-21T06:53:52Z")

</div>

That works for some things, but if a class inherits from `vtkWriter`, such functionality is “orphaned”. AFAICT, the vast majority of the writer classes are in this bucket. So, you can probably get “VTK” format output in such a way, but not something like PLY or GeoJSON.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [March 21, 2022, 6:57am UTC](https://discourse.vtk.org/t/vtkwriter-to-memory/8087/5 "2022-03-21T06:57:24Z")

</div>

Agreed, only vtkDataWriter has this capabilities afaik.

---

<div class="post-metadata">

### Author: ![whophil](https://discourse.vtk.org/user_avatar/discourse.vtk.org/whophil/32/2857_2.png) [@whophil](https://discourse.vtk.org/u/whophil)
#### Post date: [March 21, 2022, 10:13pm UTC](https://discourse.vtk.org/t/vtkwriter-to-memory/8087/6 "2022-03-21T22:13:34Z")

</div>

Thanks for the answer and discussion!
