CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 1999
    Location
    Sweden
    Posts
    30

    allocating memory

    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


  2. #2
    Join Date
    Apr 1999
    Location
    Miami, FL
    Posts
    67

    Re: allocating memory

    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

  3. #3
    Join Date
    May 1999
    Location
    Sydney, Australia
    Posts
    420

    Re: allocating memory

    Alvaro's method is good, or craete tham as you need them and put them into a CObList

    Sally


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured