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:
@@ -14,6 +14,7 @@ Changes in behaviour not resulting in compilation errors, please read this!
|
|||||||
if the whole name is a directory.
|
if the whole name is a directory.
|
||||||
- wxDialog::CreateButtonSizer() may return NULL now, please see the manual.
|
- wxDialog::CreateButtonSizer() may return NULL now, please see the manual.
|
||||||
- wxStaticBoxSizer now deletes the associated wxStaticBox when it is deleted.
|
- 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
|
- Windows calling CaptureMouse() are now required to handle the
|
||||||
wxEVT_MOUSE_CAPTURE_LOST event and not call ReleaseMouse() in this case.
|
wxEVT_MOUSE_CAPTURE_LOST event and not call ReleaseMouse() in this case.
|
||||||
|
|
||||||
|
@@ -493,7 +493,8 @@ append a lot of items.
|
|||||||
Preallocates memory for a given number of array elements. It is worth calling
|
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
|
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
|
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}
|
\membersection{wxArray::Clear}\label{wxarrayclear}
|
||||||
|
|
||||||
|
@@ -169,7 +169,7 @@ public: \
|
|||||||
\
|
\
|
||||||
void Empty() { m_nCount = 0; } \
|
void Empty() { m_nCount = 0; } \
|
||||||
void Clear(); \
|
void Clear(); \
|
||||||
void Alloc(size_t uiSize); \
|
void Alloc(size_t n) { if ( n > m_nSize ) Realloc(n); } \
|
||||||
void Shrink(); \
|
void Shrink(); \
|
||||||
\
|
\
|
||||||
size_t GetCount() const { return m_nCount; } \
|
size_t GetCount() const { return m_nCount; } \
|
||||||
@@ -225,7 +225,7 @@ protected: \
|
|||||||
void insert(iterator it, const_iterator first, const_iterator last);\
|
void insert(iterator it, const_iterator first, const_iterator last);\
|
||||||
void pop_back() { RemoveAt(size() - 1); } \
|
void pop_back() { RemoveAt(size() - 1); } \
|
||||||
void push_back(const value_type& v) { Add(v); } \
|
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()) \
|
void resize(size_type n, value_type v = value_type()) \
|
||||||
{ SetCount(n, v); } \
|
{ SetCount(n, v); } \
|
||||||
\
|
\
|
||||||
|
@@ -244,23 +244,6 @@ void name::Clear() \
|
|||||||
wxDELETEA(m_pItems); \
|
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 */ \
|
/* minimizes the memory usage by freeing unused memory */ \
|
||||||
void name::Shrink() \
|
void name::Shrink() \
|
||||||
{ \
|
{ \
|
||||||
|
@@ -149,6 +149,7 @@ private:
|
|||||||
CPPUNIT_TEST( wxArrayUShortTest );
|
CPPUNIT_TEST( wxArrayUShortTest );
|
||||||
CPPUNIT_TEST( wxArrayIntTest );
|
CPPUNIT_TEST( wxArrayIntTest );
|
||||||
CPPUNIT_TEST( TestSTL );
|
CPPUNIT_TEST( TestSTL );
|
||||||
|
CPPUNIT_TEST( Alloc );
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
|
|
||||||
void wxStringArrayTest();
|
void wxStringArrayTest();
|
||||||
@@ -156,6 +157,7 @@ private:
|
|||||||
void wxArrayUShortTest();
|
void wxArrayUShortTest();
|
||||||
void wxArrayIntTest();
|
void wxArrayIntTest();
|
||||||
void TestSTL();
|
void TestSTL();
|
||||||
|
void Alloc();
|
||||||
|
|
||||||
DECLARE_NO_COPY_CLASS(ArraysTestCase)
|
DECLARE_NO_COPY_CLASS(ArraysTestCase)
|
||||||
};
|
};
|
||||||
@@ -359,6 +361,20 @@ TestArrayOf(UShort);
|
|||||||
|
|
||||||
TestArrayOf(Int);
|
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()
|
void ArraysTestCase::TestSTL()
|
||||||
{
|
{
|
||||||
wxArrayInt list1;
|
wxArrayInt list1;
|
||||||
|
Reference in New Issue
Block a user