|
-
January 19th, 2011, 11:47 AM
#1
Which is better CStringArray or CString concatenate with delimiter
Hi
i want to store all the elements of the list box, but i don't know what's the best way to store in the memory. Should i store in CStringArray or Concatenate all the elements of the listbox with a delimiter say comma and split to retrieve the elements. Please tell me which is the best way and which will take less memory.
Regards
Abhishek Madaan
-
January 19th, 2011, 11:57 AM
#2
Re: Which is better CStringArray or CString concatenate with delimiter
Please tell me which is the best way and which will take less memory.
Less memory ? Why is that important ? It are some strings from a listbox, not a 300 megabyte file. Memory consumption these days isn't really an issue anymore. A stringlist is much easier to manage than cutting and pasting data from a single string.
-
January 19th, 2011, 12:06 PM
#3
Re: Which is better CStringArray or CString concatenate with delimiter
I don't think so it will go upto 300 MegaByte but still in my application can create 100 of listboxes with 100 or more listbox string in each listbox. So that's why i want to use the best method.
Regards
ABM
-
January 19th, 2011, 12:22 PM
#4
Re: Which is better CStringArray or CString concatenate with delimiter
Well.. lets say each string is 50 chars and each listbox has 1000 items and you have 100 listboxes. That is still only 5 MB. But to answer you question... A stringlist doesn't has that much overhead but it is much easier to use.
-
January 19th, 2011, 12:29 PM
#5
Re: Which is better CStringArray or CString concatenate with delimiter
-
January 19th, 2011, 12:48 PM
#6
Re: Which is better CStringArray or CString concatenate with delimiter
A CStringArray would be much easier to use.
It will reserve extra space so that it does not need to continually increase
allocated space and copy the contents from the current memory to the new
allocated memory (CString will do the same). The extra space is not very large.
You can use trhe FreeExtra() member function to remove it.
-
January 19th, 2011, 01:14 PM
#7
Re: Which is better CStringArray or CString concatenate with delimiter
The strings are already in the list box. Why do you need to store them twice?
-
January 19th, 2011, 01:44 PM
#8
Re: Which is better CStringArray or CString concatenate with delimiter
 Originally Posted by GCDEF
The strings are already in the list box. Why do you need to store them twice?
If you would make an owner-drawn listbox you could add empty strings in the first place and provide the real strings from an array only for the visible items. That way you also could spare a redundant storing and the initial load of the listbox goes much faster.
BTW, I have not so good experiences with huge listboxes as they badly were accepted by the Users especially if they have entries with many similar prefixes. You might think of a tree control instead or of a possibility to filtering the entries by the User.
-
January 19th, 2011, 01:50 PM
#9
Re: Which is better CStringArray or CString concatenate with delimiter
 Originally Posted by ABM
Hi
i want to store all the elements of the list box, but i don't know what's the best way to store in the memory.
The basic question that needs to be asked is a GUI component (listbox) driving the way you store or retrieve your data?
If this is the case, then what if in another version, the list boxes are replaced with something else? Do you then redesign your data to fit this new component? Choose the container that makes the most sense, given the business logic. Then figure out how to get that GUI to fit the business design/logic.
Too many times, I see programmers designing their data to fit a GUI, and they have to scrap the whole thing when it comes time to provide a different GUI, or a new requirement is made to provide a command-line version of the applcation. Hopefully you're not making this same mistake.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; January 19th, 2011 at 01:52 PM.
-
January 19th, 2011, 02:21 PM
#10
Re: Which is better CStringArray or CString concatenate with delimiter
 Originally Posted by Paul McKenzie
The basic question that needs to be asked is a GUI component (listbox) driving the way you store or retrieve your data?
If this is the case, then what if in another version, the list boxes are replaced with something else? Do you then redesign your data to fit this new component? Choose the container that makes the most sense, given the business logic. Then figure out how to get that GUI to fit the business design/logic.
Too many times, I see programmers designing their data to fit a GUI, and they have to scrap the whole thing when it comes time to provide a different GUI, or a new requirement is made to provide a command-line version of the applcation. Hopefully you're not making this same mistake.
Regards,
Paul McKenzie
I asked the question if he already has the data in the list box, why he needs to store it again in an array. The implication is he's kind of got the cart before the horse. If he's already got the data in the list box, it's already coming from somewhere. As you say, the list is just a view of the data. Loading the list box, then storing the data from the list box seems a little odd to me. I'd like more info on what the OP is up to.
itsmeandnobodyelse, I was asking the OP why he wants to do what he's doing, not looking for a third-party hypothetical. Again, if he didn't already have the data, he couldn't populate the list box.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|