________________________________
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Lawrence,
Scott (BL60:9D30)
Sent: Friday, November 07, 2008 5:30 PM
To: sipx-dev
Subject: [sipX-dev] new UtlString method to set content length
directly
In reviewing a proposed patch from Raymond, I was reminded that
I keep meaning to propose a change to UtlString that will reduce the
need for a number of data copies (sometimes large ones).
The primitive I'd like to add is one to directly set the length
of the data in the buffer; we already have a method to get the pointer
to the buffer (UtlString::data), so it's possible to get that pointer
and write to it, and we have a method to ensure that the buffer can hold
a given size (UtlString::capacity). All that's missing is a way to
directly write content into the buffer and then after the fact tell the
UtlString how much data you put there. There are many places in the
code now where we create an intermediate variable (sometimes a big one)
that we can write into just so that we can then copy it again using one
of the append methods of UtlString.
Here's the description I propose:
void setLength ( size_t newLength )
Set a new length for the content.
This does NOT modify the data in the buffer - it
only resets the value that would be returned by UtlString::length
<file:///home/INST-SDL/xecs-patch/share/doc/sipxecs/sipxportlib/class_ut
l_string.html#2edf269e5cd490f7863c9150bb910c85> . The newLength value
MUST be <= UtlString::capacity
<file:///home/INST-SDL/xecs-patch/share/doc/sipxecs/sipxportlib/class_ut
l_string.html#e3b0b3ce67788bf2e4e209f65eb99297> .
This allows external code to directly manipulate
the contents of buffer and adjust the UtlString
<file:///home/INST-SDL/xecs-patch/share/doc/sipxecs/sipxportlib/class_ut
l_string.html> data accordingly. For example, the following sets the
'buffer' to contain a 'sizeNeeded' number of bytes of all one bits:
UtlString
<file:///home/INST-SDL/xecs-patch/share/doc/sipxecs/sipxportlib/class_ut
l_string.html> buffer;
if (buffer.capacity
<file:///home/INST-SDL/xecs-patch/share/doc/sipxecs/sipxportlib/class_ut
l_string.html#e3b0b3ce67788bf2e4e209f65eb99297> (sizeNeeded) >=
sizeNeeded)
{
memset(buffer.data
<file:///home/INST-SDL/xecs-patch/share/doc/sipxecs/sipxportlib/class_ut
l_string.html#3030b6aaaab96d31eb5b62c44a54aeaf> (), 0xff, sizeNeeded);
buffer.setLength
<file:///home/INST-SDL/xecs-patch/share/doc/sipxecs/sipxportlib/class_ut
l_string.html#5d975449d822e798d70a93a0eb4ffb5e> (sizeNeeded);
}
[<<BOB JOLY>>] This makes sense but in reading the example, I
wonder about null-termination considerations, if any When we set the
content of the data buffer 'manually', must we supply a NULL
termination? Should the capacity() value we specify account for the
NULL termination? When I set the length, does that exclude the NULL
termination?
_______________________________________________
sipx-dev mailing list
[email protected]
List Archive: http://list.sipfoundry.org/archive/sipx-dev
Unsubscribe: http://list.sipfoundry.org/mailman/listinfo/sipx-dev