[LLVMdev] [PATCH] Circular Buffered Debug Stream
Chris Lattner
clattner at apple.com
Tue Dec 22 17:00:26 PST 2009
On Dec 21, 2009, at 12:20 PM, David Greene wrote:
>>> + /// flushBuffer - Dump the contents of the buffer to Stream.
>>> + ///
>>> + void flushBuffer(void) {
>>> + // Write the older portion of the buffer.
>>> + TheStream->write(Cur, BufferArray + BufferSize - Cur);
>>> + // Write the newer portion of the buffer.
>>> + TheStream->write(BufferArray, Cur - BufferArray);
>>> + Cur = BufferArray;
>>> + }
>>
>> Is this correct in the case when the circular buffer hasn't
>> completely
>> filled yet?
>
> Hmm...Depends on what's "correct." :) You'll get a bunch of garbage
> output but I don't think it should fault or anything. I don't think
> there's a way of knowing whether the buffer got filled all the way to
> the end unless we add another member variable. In practice, it will
> almost always be filled.
Correct is not emitting garbage. Adding another member is worth it.
Saving 4 bytes per circular_raw_ostream doesn't matter when you have a
multi kilobyte buffer it is managing.
Aside from that, your patch looks fine. Please fix this and commit it,
-Chris
More information about the llvm-dev
mailing list