Solved

CStringArray???

Posted on 1998-10-16
3
1,290 Views
Last Modified: 2013-11-20
Hi,

I have the following problems:

1.) Is there a upper limit of the size of assigning a         CtringArray?
    eg. CStringArray data;
        data.SetSize(?);
2.) Is it possible to have a two-dimensional CStringArray?

3.) Besides using SetSize to allocate the size, can I use
    "new" to allocate the size.
    e.g.  CStringArray data = new CStringArray [1000];

Thanks!!!
0
Comment
Question by:cplau
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
plaroche earned 40 total points
ID: 1323399
1.) The practical limit is based on the computer running your code. Available ram, etc...
If you check CObArray's source code in AFXCOLL.H you will see that the size is an integer, so the max size is based on this value.

2.) Nope. CStringArray comes from CObArray, this is a one dimension array.

3.) CStringArray does not support size spec in its constructor. Besides the syntax you propose is flawed:

  CStringArray* pArray = new CStringArray;
  // Use it to do what you want and then delete it
  delete pArray;

0
 

Author Comment

by:cplau
ID: 1323400
Hi Sir,

I want to ask whether I need to free the memory after using CStringArray in a class.
eg. in the myfile.h, I have declared CStringArray temp;

then in the myfile.cpp I have delcared : temp.SetSize(1000) and initialize the array in the
function.

Do I need to free the memory after exiting the function?

Thanks
                                                         

0
 
LVL 3

Expert Comment

by:plaroche
ID: 1323401
What goes into a CStringArray are string that you have allocated. Thus you need to free those strings but you don't need to worry about the array, unless you've allocated it with new.

Example:

CStringArray* pArray = new CStringArray;  // will have to be freed
CStringArray array; // Won't have to be freed.

// What goes into those arrays are allocated strings.
CString* pString = new CString;

pArray->Add(pString);
array.Add(pString);`

pArray->RemoveAll();
array.RemoveAll();

delete pString;

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Host to IP 7 78
Use of condition with 'serial' in ansible 2 60
wordcount challenge 11 121
"Black Box" Testing of Control System Software 2 51
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question