[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.2

How do I deallocate a two-dimensional vector (STL) of wchar_t* type

Asked by DataField in C++ Programming Language, Microsoft Visual C++

Tags: vector, deallocate, dimensional, stl, two

I'm reading in a file, line by line.  Each line contains values delimited by a colon.  I won't know how many lines are going to be in the file, but I DO know how many values are going to be delimited for each line.  After tokenizing each line, I'm trying to store the values in a two-dimensional array using STL's <vector>.  Each entry in the array contains another vector array of wide char pointers that will each point to a newly allocated wide char string.  I'm having trouble deallocating the vector.  Currently, I have something like the following.

// Channels is defined like this...
vector< vector<wchar_t*> >  Channels;

// Reading in the data goes something like this...

    // Read data in, line by line.
    while ( ReadLine(hFile, szwLine) > 0 ) {
       
        if ( wcsstr(szwLine, L"CHANNEL=") != NULL ) {

            // Create a new index for Channel array.
            g_stAI.Channels.push_back( vector<wchar_t*>() );

            // Determine if line read in is a channel place holder.
            if ( wcsstr(szwLine, L"PLACEHOLDER") != NULL ) {
                pTemp = new wchar_t[wcslen(L"PLACEHOLDER")*sizeof(wchar_t)+1];
                wcscpy( pTemp, L"PLACEHOLDER" );
                g_stAI.Channels[iCount].push_back( pTemp );
               
            } else {
                // Parse data
                pDummy       = wcstok( szwLine, L"=" );
                pChanName    = wcstok( NULL,    L":" );
                pChanID      = wcstok( NULL,    L":" );
                pChanUseHigh = wcstok( NULL,    L":" );
                pChanHighVal = wcstok( NULL,    L":" );
                pChanUseLow  = wcstok( NULL,    L":" );
                pChanLowVal  = wcstok( NULL,    L":" );

                pTemp = new wchar_t[wcslen(pChanName)*sizeof(wchar_t)+1];
                wcscpy( pTemp, pChanName );
                g_stAI.Channels[iCount].push_back( pTemp );

                pTemp = new wchar_t[wcslen(pChanID)*sizeof(wchar_t)+1];
                wcscpy( pTemp, pChanID );
                g_stAI.Channels[iCount].push_back( pTemp );

                pTemp = new wchar_t[wcslen(pChanUseHigh)*sizeof(wchar_t)+1];
                wcscpy( pTemp, pChanUseHigh );
                g_stAI.Channels[iCount].push_back( pTemp );

                pTemp = new wchar_t[wcslen(pChanHighVal)*sizeof(wchar_t)+1];
                wcscpy( pTemp, pChanHighVal );
                g_stAI.Channels[iCount].push_back( pTemp );

                pTemp = new wchar_t[wcslen(pChanUseLow)*sizeof(wchar_t)+1];
                wcscpy( pTemp, pChanUseLow );
                g_stAI.Channels[iCount].push_back( pTemp );

                pTemp = new wchar_t[wcslen(pChanLowVal)*sizeof(wchar_t)+1];
                wcscpy( pTemp, pChanLowVal );
                g_stAI.Channels[iCount].push_back( pTemp );
            }
            iCount++;
        }
    }


When I'm ready to deallocate all values in the vector, how would I go about it?  If someone could help me out, I would surely appreciate it.  If possible, please post code for the deallocation.  Or if anyone knows of a simpler way to do this, please let me know.

Any help would be much appreciated.
Thanks
[+][-]05/03/05 10:15 AM, ID: 13919769Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: C++ Programming Language, Microsoft Visual C++
Tags: vector, deallocate, dimensional, stl, two
Sign Up Now!
Solution Provided By: jkr
Participating Experts: 2
Solution Grade: A
 
[+][-]05/03/05 10:17 AM, ID: 13919787Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/03/05 10:31 AM, ID: 13919910Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/03/05 10:49 AM, ID: 13920050Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/03/05 01:59 PM, ID: 13921674Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/03/05 02:16 PM, ID: 13921807Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/03/05 02:21 PM, ID: 13921839Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/03/05 07:23 PM, ID: 13923460Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89