• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1455
  • Last Modified:

CStringArray???

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
cplau
Asked:
cplau
  • 2
1 Solution
 
plarocheCommented:
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
 
cplauAuthor Commented:
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
 
plarocheCommented:
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now