]> git.saurik.com Git - wxWidgets.git/commitdiff
Implemented wxArrayString::Shrink() and stuff.
authorOve Kaaven <ovek@arcticnet.no>
Thu, 15 Apr 1999 10:11:31 +0000 (10:11 +0000)
committerOve Kaaven <ovek@arcticnet.no>
Thu, 15 Apr 1999 10:11:31 +0000 (10:11 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2170 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/string.cpp

index 85560f9d65f3ad3aa6f0f5276f4f8d2a2471a3a9..4d806122807b084dbaf9580f99e245f233bbd408 100644 (file)
@@ -1627,6 +1627,21 @@ void wxArrayString::Alloc(size_t nSize)
   m_nCount = 0;
 }
 
+// minimizes the memory usage by freeing unused memory
+void wxArrayString::Shrink()
+{
+  // only do it if we have some memory to free
+  if( m_nCount < m_nSize ) {
+    // allocates exactly as much memory as we need
+    wxChar **pNew = new wxChar *[m_nCount];              
+
+    // copy data to new location
+    memcpy(pNew, m_pItems, m_nCount*sizeof(wxChar *));
+    delete [] m_pItems;
+    m_pItems = pNew;
+  }
+}
+
 // searches the array for an item (forward or backwards)
 int wxArrayString::Index(const wxChar *sz, bool bCase, bool bFromEnd) const
 {
@@ -1920,7 +1935,7 @@ static void wxLoadCharacterSets(void)
 {
   static bool already_loaded = FALSE;
 
-#ifdef __UNIX__
+#if defined(__UNIX__) && wxUSE_UNICODE
   // search through files in /usr/share/i18n/charmaps
   for (wxString fname = ::wxFindFirstFile(_T("/usr/share/i18n/charmaps/*"));
        !fname.IsEmpty();