Link to home
Start Free TrialLog in
Avatar of cplau
cplau

asked on

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!!!
ASKER CERTIFIED SOLUTION
Avatar of plaroche
plaroche

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cplau
cplau

ASKER

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
                                                         

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;