loadFile won't load the datasource into memory, it's actually done by getBuffer. The first time you call getBuffer an internal Buffer member is created in the datasource and it's contents are filled from it. Subsequent calls to getBuffer will return this internal member.
The lifetime of the internal member is linked to the lifetime of the datasource. In the example above the Buffer reference will be invalidated when the datasource is destroyed.
You can obtain a lasting reference to the internal buffer by assigning the result of getBuffer to a buffer instance. In this way you can use the buffer data without it being tied to the lifetime of the datasource:
- DataSourceRef data = loadFile("myvideo");
- Buffer buf = data->getBuffer();
Using the Buffer constructor with a datasource will construct the internal buffer *and* return a new copy of its data. Use this when you need a new copy of the data that is independent of the original buffer.
Buffer has different behaviours depending on how it is constructed, it's worth flicking through the source to figure out how the different constructors affect the way it manages memory.
For read-only purposes the snippet above is the safest and most memory efficient way to get a buffer from a datasource.