Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

How to seek a GrowBuffer?

Moderators: larsivi kris

Posted: 12/06/07 11:27:30


The MemoryConduit? says to use GrowBuffer?, but it is not seekable, or at least I don't know how to seek it.

Thanks, bobef

Author Message

Posted: 12/08/07 00:20:24 -- Modified: 12/08/07 00:21:05 by

I don't think MemoryConduit was seekable either? At least, I can't find any evidence that it was. Did you need to access the GrowBuffer content as an indexed array, or similar?

Posted: 12/08/07 17:51:41

I don't think MemoryConduit? was seekable either? At least, I can't find any evidence that it was

I thought so about MemoryConduit? because file conduit is seekable and it also a conduit (whatever that is :).

Did you need to access the GrowBuffer? content as an indexed array, or similar?

Yes, I am using FMOD's feature of custom file system and it needs seeking. Also, GrowBuffer? is just a memory buffer, isn't it? So what is the problem with it being seekable? I solved it like this:

class GrowBuffer2 : GrowBuffer
	this(uint a,uint b){super(a,b);}
	bool seek(uint pos)
		if(pos>extent) return false;
		else index=pos;
		return true;

Posted: 12/08/07 18:11:26

Files are actually a special case of a stream, since most other devices do not support seek (think about network connections and so on). Buffer itself represents a generic stream with limited (windowed) seeking using skip(), but it does not reflect the kind of seeking that File can explicitly support.

However, since Buffer does expose the memory involved, you can use that to directly access the content in whatever specific manner you choose. That includes specializing/deriving in the manner you have described, or simply by using Buffer.getContent to return the array being populated (or Buffer.slice to get the valid content thus far). It may be that GrowBuffer? should have a simple form of setting the current index, as you indicate.

As for 'conduit', it is just a name for something that plays host to a pair of streams: an input stream and an output stream. You could call it a 'device' instead. As long as something has both an input and an output stream, it is considered to be a conduit rather than just a simple stream.