Lifetime of File and FileOutputStream object


Sorry for noob question.

Say I want to create a file stream to write to:

File WaveFile("juce.wav");

FileOutputStream Stream(WaveFile);

Do I need to keep WaveFile object alive until Stream is closed and deleted or I can remove it as soon as Stream is created?

P.S. Does someone know any reasonable Juce documentation? API reference is not a sufficient one...

Thank you.








FileOutputStream makes a copy of the File object you pass to it. You can see this in the constructor for FileOutputStream; this is done in the initializer list. The FileOutputStream keeps its own private File object, so you don't need to keep WaveFile around. You can tell this by reading the source code (juce_FileOutputStream.cpp).

You might start with the JUCE book:

However, questions like this are probably best answered by having a good understanding of C++ and reading the source code. In fact, if you want to understand JUCE well, you must read the source.

Thank you for response. It is a pity that there is no good online documentation for Juce.

I had something like 15 years programming with VCL and had to cope with source code maybe 5 times. During 3 years of working with Qt I only needed to dig into source once.

And with Juce I have go inside Juce code writing my first 5 lines...


It is a pity that there is no good online documentation for Juce.

This comment comes up all the time here, and I don't know what to tell you. When I first started using JUCE, I was like, "wow, an open source project that actually has documentation!" I was literally blown away at how many comments were in the header files.

Yes, Qt has good documentation, but reading the JUCE source has many advantages. The entire source is imported and compiled as part of every project, so it's easy to step debug to find problems; you'll eventually get hit by a jassert() that will help you correct a programming mistake. It's easy to find declarations/definitions of anything in the juce namespace by using your IDE (F12 in Visual Studio, F3 in Eclipse, F2 in QtCreator, etc). A lot of the craziness in Qt like the signals and slots mechanism (and the effing Meta Object Compiler) can make debugging difficult; JUCE is just C++. Good variable names and coding style make reading the source fairly straightforward.

Sounds like you've got some solid dev skills; don't let the documentation thing scare you away.