Solved

CStringArray???

Posted on 1998-10-16
3
1,241 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Login Script to Copy Folders 12 20
substring method in java 1 79
NotAlone Challenge 20 70
unix example issues 18 44
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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 video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now