+
+ return TRUE;
+}
+
+// allocate enough memory for nLen characters
+bool wxString::Alloc(size_t nLen)
+{
+ wxStringData *pData = GetStringData();
+ if ( pData->nAllocLength <= nLen ) {
+ if ( pData->IsEmpty() ) {
+ nLen += EXTRA_ALLOC;
+
+ wxStringData* pData = (wxStringData*)
+ malloc(sizeof(wxStringData) + (nLen + 1)*sizeof(wxChar));
+
+ if ( pData == NULL ) {
+ // allocation failure handled by caller
+ return FALSE;
+ }
+
+ pData->nRefs = 1;
+ pData->nDataLength = 0;
+ pData->nAllocLength = nLen;
+ m_pchData = pData->data(); // data starts after wxStringData
+ m_pchData[0u] = wxT('\0');
+ }
+ else if ( pData->IsShared() ) {
+ pData->Unlock(); // memory not freed because shared
+ size_t nOldLen = pData->nDataLength;
+ if ( !AllocBuffer(nLen) ) {
+ // allocation failure handled by caller
+ return FALSE;
+ }
+ memcpy(m_pchData, pData->data(), nOldLen*sizeof(wxChar));
+ }
+ else {
+ nLen += EXTRA_ALLOC;
+
+ pData = (wxStringData *)
+ realloc(pData, sizeof(wxStringData) + (nLen + 1)*sizeof(wxChar));
+
+ if ( pData == NULL ) {
+ // allocation failure handled by caller
+ // keep previous data since reallocation failed
+ return FALSE;
+ }
+
+ // it's not important if the pointer changed or not (the check for this
+ // is not faster than assigning to m_pchData in all cases)
+ pData->nAllocLength = nLen;
+ m_pchData = pData->data();
+ }
+ }
+ //else: we've already got enough
+ return TRUE;
+}
+
+// shrink to minimal size (releasing extra memory)
+bool wxString::Shrink()
+{
+ wxStringData *pData = GetStringData();
+
+ size_t nLen = pData->nDataLength;
+ void *p = realloc(pData, sizeof(wxStringData) + (nLen + 1)*sizeof(wxChar));
+
+ if ( p == NULL) {
+ wxFAIL_MSG( _T("out of memory reallocating wxString data") );
+ // keep previous data since reallocation failed
+ return FALSE;
+ }
+
+ if ( p != pData )
+ {
+ // contrary to what one might believe, some realloc() implementation do
+ // move the memory block even when its size is reduced
+ pData = (wxStringData *)p;
+
+ m_pchData = pData->data();
+ }
+
+ pData->nAllocLength = nLen;
+
+ return TRUE;