Click to See Complete Forum and Search --> : allocating memory


odin
April 20th, 1999, 01:56 PM
If I do a CListCtrl m_wndList[20]; would this allocate alot of memory if the user only "makes" the program use the first two.. for example
(it sure is ugly to do like this!)

The thing is i dont know from the start how many ctabctrl's the user needs,, its up to him...

-- Henrik

Alvaro
April 20th, 1999, 05:21 PM
I'm not sure how much memory or time it would take to allocate 20 CListCtrls on the stack but I doubt it's much. Try it and see.

If you really want to play it conservatively, use an array of pointers (CListCtrl* m_pWndList[20]) and allocate each control as needed (and only once). So you'll just need to remember to first initialize the array in your constructor (memset(m_pWndList, 0, sizeof(m_pWndList);) and then clean it in your destructor:


for (int i = 0; i < sizeof(m_pWndList) / sizeof(*m_pWndList); i++)
{
if (m_pWndList[ i ])
delete m_pWndList[ i ];
}




That's the price for conservatism... but it may be worth it.


Alvaro

sally
April 20th, 1999, 06:42 PM
Alvaro's method is good, or craete tham as you need them and put them into a CObList

Sally

Sally
April 20th, 1999, 06:42 PM
Alvaro's method is good, or craete tham as you need them and put them into a CObList

Sally