Quote Originally Posted by Marc G View Post
I don't quite understand your design.
Apparently you have a class with your buffer in it.
Can't you instantiate 1 instance of that class for every thread?
That way, each thread has its own buffer.
How about something like this?

Code:
template<class T>struct Buff {
	size_t size;
	T* t;

	Buff() : size(0),t(0) {}

	Buff(size_t n) : size(0),t(0)
	{
		t = new T[n];
		if(t)
			size = n;
	}

	bool operator!()
	{
		return !t;
	}

	T& operator[](size_t i)
	{
		if(i >= 0 && i < size)
			return t[i];
		throw "index out of range";
	}

	const T& operator[](size_t i) const
	{
		if(i >= 0 && i < size)
			return t[i];
		throw "index out of range";
	}
		
	~Buff()
	{
		size = 0;
		if(t)
			delete [] t;
		t = 0;
	}
};
To get a char buffer declare a variable in your thread like:

Code:
#define BUFSIZE 4096
Buff<char> buffer(BUFSIZE);

You can spiff it up with iterators or dereferencing '*' operator or whatnot.
When it goes out of scope, the memory is freed.