Alloc() doesn't clear the array any more, for consistency with reserve()

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42571 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2006-10-28 14:16:20 +00:00
parent 84498436c9
commit 7788fc4046
5 changed files with 21 additions and 20 deletions

View File

@@ -14,6 +14,7 @@ Changes in behaviour not resulting in compilation errors, please read this!
if the whole name is a directory.
- wxDialog::CreateButtonSizer() may return NULL now, please see the manual.
- wxStaticBoxSizer now deletes the associated wxStaticBox when it is deleted.
- wxArray::Alloc() now works as reserve() and does not clear the array any more
- Windows calling CaptureMouse() are now required to handle the
wxEVT_MOUSE_CAPTURE_LOST event and not call ReleaseMouse() in this case.

View File

@@ -493,7 +493,8 @@ append a lot of items.
Preallocates memory for a given number of array elements. It is worth calling
when the number of items which are going to be added to the array is known in
advance because it will save unneeded memory reallocation. If the array already
has enough memory for the given number of items, nothing happens.
has enough memory for the given number of items, nothing happens. In any case,
the existing contents of the array is not modified.
\membersection{wxArray::Clear}\label{wxarrayclear}

View File

@@ -169,7 +169,7 @@ public: \
\
void Empty() { m_nCount = 0; } \
void Clear(); \
void Alloc(size_t uiSize); \
void Alloc(size_t n) { if ( n > m_nSize ) Realloc(n); } \
void Shrink(); \
\
size_t GetCount() const { return m_nCount; } \
@@ -225,7 +225,7 @@ protected: \
void insert(iterator it, const_iterator first, const_iterator last);\
void pop_back() { RemoveAt(size() - 1); } \
void push_back(const value_type& v) { Add(v); } \
void reserve(size_type n) { if(n > m_nSize) Realloc(n); } \
void reserve(size_type n) { Alloc(n); } \
void resize(size_type n, value_type v = value_type()) \
{ SetCount(n, v); } \
\

View File

@@ -244,23 +244,6 @@ void name::Clear() \
wxDELETEA(m_pItems); \
} \
\
/* pre-allocates memory (frees the previous data!) */ \
void name::Alloc(size_t nSize) \
{ \
/* only if old buffer was not big enough */ \
if ( nSize > m_nSize ) { \
wxDELETEA(m_pItems); \
m_nSize = 0; \
m_pItems = new T[nSize]; \
/* only alloc if allocation succeeded */ \
if ( m_pItems ) { \
m_nSize = nSize; \
} \
} \
\
m_nCount = 0; \
} \
\
/* minimizes the memory usage by freeing unused memory */ \
void name::Shrink() \
{ \

View File

@@ -149,6 +149,7 @@ private:
CPPUNIT_TEST( wxArrayUShortTest );
CPPUNIT_TEST( wxArrayIntTest );
CPPUNIT_TEST( TestSTL );
CPPUNIT_TEST( Alloc );
CPPUNIT_TEST_SUITE_END();
void wxStringArrayTest();
@@ -156,6 +157,7 @@ private:
void wxArrayUShortTest();
void wxArrayIntTest();
void TestSTL();
void Alloc();
DECLARE_NO_COPY_CLASS(ArraysTestCase)
};
@@ -359,6 +361,20 @@ TestArrayOf(UShort);
TestArrayOf(Int);
void ArraysTestCase::Alloc()
{
wxArrayInt a;
a.Add(17);
a.Add(9);
CPPUNIT_ASSERT_EQUAL( 2u, a.GetCount() );
a.Alloc(1000);
CPPUNIT_ASSERT_EQUAL( 2u, a.GetCount() );
CPPUNIT_ASSERT_EQUAL( 17, a[0] );
CPPUNIT_ASSERT_EQUAL( 9, a[1] );
}
void ArraysTestCase::TestSTL()
{
wxArrayInt list1;