Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

CStringArray???

Posted on 1998-10-16
3
Medium Priority
?
1,428 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

618 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