One of the optimization projects I'm working on right now makes extensive use of EPANet. We make repeated calls to two simulation methods in EPANet to understand how water flows through a water distribution network.
HydraulicSim is one of the classes we make use of. See the overloaded simulate methods:
public void simulate(File hyd) throws ENException {
...
}
public void simulate(OutputStream out) throws ENException, IOException {
...
}
public void simulate(DataOutput out) throws ENException, IOException {
...
}
The other class we use is QualitySim. Here, we also use the overloaded simulate methods:
public void simulate(File hydFile, File qualFile) throws IOException, ENException {
...
}
void simulate(File hydFile, OutputStream out) throws IOException, ENException {
...
}
Here's what we're currently doing:
- Create two
Fileobjects,hydFileandqualFile. - Call
HydraulicSim.simulateonhydFile. - Call
QualitySim.simulateonhydFileandqualFile. - Delete the files.
The problem is that we have to do this a lot of times. For a large problem, we can do this hundreds of thousands or even millions of times. You can imagine the slowdown repeatedly creating/writing/deleting these files causes.
So my question is this: Is it possible for me to create these files so that they reside only in memory and never touch the disk? Each file is very small (I'm talking a few hundred bytes), so throwing them into memory won't be a problem; I just need to figure out how. I searched around and didn't really find much, save for MappedByteBuffer, but I'm not sure how, or if it's even possible, to create a File from that class.
Any advice is welcome!
QualitySim.simulatemethod that took the streams as params (which they do for the output stream but not the input stream) you could bypass the FS. Or just fork it and do it yourself.