The CBuffer class provides a combination of easy thread-safe buffer and string methods that make it convenient in many situations. It is used to package messages with the CSock Class, whether the payload is binary or text.

Advanced CMarkup Developer License

The source code for CBuffer comes in the firstobject XML Messaging project with the Advanced CMarkup Developer License.

CBuffer uses internal reference counting to support passing it around and copying it efficiently, like the MFC CString does. In other words, you can pass it to a function by value or assign it to another CBuffer with = and though it constructs a new CBuffer it will not make a copy of the data itself unless the data is changed in one of the buffer objects. This improves the efficiency of staging the buffer during the asynchronous send and receive process. CBuffer does this using an internally managed structure called CBufferInstance which contains the data. For example, in the following code you end up with two CBuffer objects referencing one CBufferInstance.

CBuffer buf1, buf2 = "1234";
buf1 = buf2;

You can set the data of a buffer from a string, another buffer, or from a void* memory block. The GetViewable() method returns a hexidecimal string.