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.
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}
\
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; } \
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); } \
\
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() \
{ \
CPPUNIT_TEST( wxArrayUShortTest );
CPPUNIT_TEST( wxArrayIntTest );
CPPUNIT_TEST( TestSTL );
+ CPPUNIT_TEST( Alloc );
CPPUNIT_TEST_SUITE_END();
void wxStringArrayTest();
void wxArrayUShortTest();
void wxArrayIntTest();
void TestSTL();
+ void Alloc();
DECLARE_NO_COPY_CLASS(ArraysTestCase)
};
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;