?
Solved

CStringArray???

Posted on 1998-10-16
3
Medium Priority
?
1,394 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
plaroche earned 120 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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

764 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