|
I have an object of
CStringArray m_arrString.
I have to add appriximatly eight (8) thousand values with the length of max 10 characters like "ABCD-EFGD" in the m_arrString using Add menthod of array, and i will sort them.
Would the CStringArray object will work fine for 8 thousand added values,
Or is there any other to handle them ,
thanks
Regards.
|
|
|
|
|
normally, it should work, as the index is an int , and so can contain up to 2147483648 values.
i'd personnaly use std::vector<> but you could ask Mr ABuenger (aKa xxx'd) about his preference...
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VCalc 3.0 soon...]
|
|
|
|
|
Thanks,
But will not it have any memory problems?
Regards.
|
|
|
|
|
zahid_ash wrote: But will not it have any memory problems?
like what ?
of course, it's take more memory than one which contain 3 or 4 strings, but if you talk about memory leaks for example, i don't think there is problems of this order...
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VCalc 3.0 soon...]
|
|
|
|
|
this is simple ...
try both ways, see how well they work, and decide yourself.
concerning memory, if you have sufficient memory on your computer there should not be any problem at all.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
If you are worried about memory and know in advance how many elements you are going to add and the max size of each element, you may want to allocate a regular C array rather than using collection classes which introduce some amount of overhead.
onwards and upwards...
|
|
|
|
|
zahid_ash wrote: I have to add appriximatly eight (8) thousand values...
Then you may want to set an initial size by first calling the SetSize() method. This would allocate a large chunk of memory once, rather than a small chunk of memory 8,000 times.
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
Another way, which I have used, is to put the strings into large memory memory buffers one after the other (with terminating zeros between each, of course) and then store pointers to them in a CArray<>.)
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
I want to do a Total Commander in Visual C++, but I didn't find any control suitable to look like a pane.Can anyone give me some hints, please?
Thanks very much.
|
|
|
|
|
Adriana Frunza wrote: I want to do a Total Commander in Visual C++
you mean, even with the 16 bits look and feel ?
look at CSplitPane for the pane...
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VCalc 3.0 soon...]
|
|
|
|
|
I'm using Visual C++ 6 unfortunately.Where can I find this class?
|
|
|
|
|
|
This is probably a bit embarrassing, but I have set up some static controls with control variables, but I have totally forgotten how to set the text based on a floating point number!
// export version
c_ExportVersion.SetWindowText(version);
works fine, as "version" is just a character string
// fieldwidth
c_BEAMWIDTH.SetWindowText(fieldwidth);
does not work fine, as "fieldwidth" is a floating point number, I've tried going via CString but that didn't work, and sprintf seemed to be the wrong idea too
(eg tried
CString str = fieldwidth;)
I'm sure this is very basic but I've been away from Windows for a while, so am still re-finding my feet.
thanks in advance
|
|
|
|
|
CString str;<br />
str.Format("%.5f",fieldwidth);<br />
c_BEAMWIDTH.SetWindowText(str);<br />
This will print your float with 5 decimals after floating point.
|
|
|
|
|
Many thanks. I don't know how I missed the "format" class member of CString, but as I said, it's been a while!
|
|
|
|
|
In continuation to Mr. Cedric Answer, you can also you wsprintf, if working on Non MFC application
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Hi
I need to exchange large Strings between my own dll and my programm.
Any Idears ??
THX
|
|
|
|
|
extern string mystring;
Or what do you mean with "exchange" ?
~RaGE();
|
|
|
|
|
If the DLL is loaded into your processes address space, you can already see each other's memory - no extra steps required. Just allocate space for the string, and pass it to a method in the DLL. Or pass the memory to a method in the DLL and have it return the string in it. Or have the DLL allocate the memory and return it to you. Etc.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
James R. Twine wrote: Or have the DLL allocate the memory and return it to you.
Don't forget the let the dll free the memory it has allocated. Every module exe/dll is resposible for its own allocated memory.
codito ergo sum
|
|
|
|
|
Actually, I abhor writing hand-off memory functions, where memory is allocated by the called function and returned from it with the understanding that the caller is now responsible for it. IME, there seems to be an "out of sight, out of mind" mentality where if the caller did not make an explicit call to a memory allocating function/operator that they are familiar with (new , malloc(...) , SysAllocString(...) , etc.), they tend not to realize that they are now responsible for deallocating it.
I tend to write functions that need memory such that they take a pointer to a previously-allocated block of memory and the size of that block. That way, it is clear that the caller manages the memory.
I was just detailing examples for the poster. Besides, I am fairly certain that a DLL loaded into your address space can allocate memory that you can free (as long as it was allocated while in the context of your process, and not another).
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
James R. Twine wrote: Besides, I am fairly certain that a DLL loaded into your address space can allocate memory that you can free
It used to be no problem, on OS like Win9x and Win2000. We had writen our own Dll who encrypted some
data returning the BYTE* pointer to the encrypted data which was freed after use in our application. Without any problems what so ever.
We then moved to WinXP and our application crashed on the the delete[] of the memory returning in a access violation.
Found this on the net:
Potential Problems When Crossing DLL Boundaries
It is not possible to allocate memory in a DLL (either explicitly with malloc / new or
implicitly with aforementioned strdup) and pass the pointer across the DLL boundary into
the process space to free it, when the DLL and the application are using different copies
of the CRT (C-RunTime) libraries. This will cause a nasty memory access violation or worse:
corrupt the heap! When you bump into an assert in the CRT lib when it tries to execute free(),
you will know you have run into this very problem.
Memory is only valid for the copy of the CRT where they were allocated. This means that when
you are using two different CRT libraries (LIBCMT.LIB and MSVCRT.LIB for example) together,
you cannot expect one to correctly free something the other has allocated. Because they most
probably are using different heap managers, the heap runs the risk of becoming corrupted when
you run the application in release mode! Pity the programmer who has to track the bug that
crashes his application this way.
So its better safe the sorrow.
codito ergo sum
|
|
|
|
|
Hello,
I've developed an application for PocketPCs. I'm using Embedded Visual C++ so I released differents versions based on the PocketPC architecture (ARM/XSCALE, MIPS, SH3...)
However, most users don't know which architecture their PPC is based on. So I'd like to ship a single setup app that will install the right version according to the PocketPC connected (via ActieSync). But I don't know how to make such a setup app.
Can someone help me?
Regards,
Allad
----
Navigator - Your best alternative to Windows Explorer
|
|
|
|
|
I often find MFC projects - also here on Code Project - where the STL is used.
Everytime i wonder why someone do this, there are equivalent classes in the MFC.
If i don't want to use the MFC ok, but if i make a control which is derived from a MFC class, why shouldn't i use MFC containers too? MFC has CMap, CArray and CList, so there is no need to use STL.
Are there any reasons to use the STL in a MFC project?
|
|
|
|
|
first of all, STL is the Standard C++ library, which means it compiles on every plateform (windows, linux, mac, solaris, etc...) without changing the code, but only recompiling...
secondly, MFC are targetted for windows, and most of the classes provided there are wrappers, which means they provides some additionnal layers (which may result in more slow code).
and finnaly, MFC classes are generally usd for display purpose (GUI oriented at least), while STL are for background treatments (controler layer of MVC model).
any more questions ?
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VCalc 3.0 soon...]
|
|
|
|