+// allocate enough memory for nLen characters
+void wxString::Alloc(uint nLen)
+{
+ wxStringData *pData = GetStringData();
+ if ( pData->nAllocLength <= nLen ) {
+ if ( pData->IsEmpty() )
+ AllocBuffer(nLen);
+ else {
+ wxStringData *p = (wxStringData *)
+ realloc(pData, sizeof(wxStringData) + (nLen + 1)*sizeof(char));
+ if ( p != NULL && p != pData ) {
+ // the call succeeded but the pointer changed
+ pData->Unlock();
+ free(pData);
+
+ p->nRefs = 1;
+ p->nAllocLength = nLen;
+ m_pchData = p->data();
+ }
+ //else: do nothing: either the call failed or the pointer is unchanged
+ }
+ }
+ //else: we've already got enough
+}
+
+// shrink to minimal size (releasing extra memory)
+void wxString::Shrink()
+{
+ wxStringData *pData = GetStringData();
+ void *p = realloc(pData, sizeof(wxStringData) +
+ (pData->nDataLength + 1)*sizeof(char));
+ if ( p == NULL ) // huh? can't unallocate memory? unlikely but possible.
+ return;
+ wxASSERT( p == pData ); // we're decrementing the size - block shouldn't move!
+}
+