|
What I asked is to verify if my code is correct and maybe suggest how to make it more valid.
I still remember claims how "highly portable", "highly standard" and "very fast" STL was back in 1999, this is really not what I was asking.
|
|
|
|
|
I never liked this kind of comparison of containers, it is not very useful partly because of the reasons I mentioned in my previous post. Different real-world scenarios can put stress on a container in a thousand different ways.
|
|
|
|
|
Alexander Fedorov wrote: What I asked is to verify if my code is correct and maybe suggest how to make it more valid. I think you will find that CodeProject members do not offer this service.
Veni, vidi, abiit domum
|
|
|
|
|
I can't comment on map/list but if the MFC array type is performing faster than an STL vector or a built in array I'd be very suspicious of what I'd written. In your vector code the push_back and exception handling (which you haven't got for the MFC case) would be my first targets for a good hard look.
|
|
|
|
|
Good point. Exception handling actually does not add anithing to the timing, because its just 1 large function that wrapped in it. I just was wondering why I cannot allocate 500M array while vectors.max_siz says it can do over 1G so basically its a leftover from some debugging. MFC CArray is actually only container that I found is 4-5 times slower than STL vector with or without try-catch block. Maybe if I add array random access to the test MFC will be winning?
|
|
|
|
|
I'm now surprised that the MFC array is so slow - I'd have thought built in, vector and CArray would all be about the same speed. I doubt adding random access will change much, provided you don't change the size a std::vector should be as fast as a built in array for random access.
|
|
|
|
|
Its only noticeably slower on really large arrays, like hundred millions of elements, probably because CArray doing unnecessary stuff like zeroing memory before using it.
|
|
|
|
|
I tried using std::map in an application that handles telemetry data. When it was not working I tried stepping into a simple call to fetch data from the map. After 100+ calls without the data I concluded the problem had been found. When the map was replaced with a simple array, the application ran with a very low CPU load.
The std::map is easy to use and a great way to get the program fundamentals right while trying to ignore the data storage problem. If speed is needed, a general and generic problem that can handle any type of data will be inherently much slower.
My conclusion: the template libraries are really cool and easy to use, but very inefficient.
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
|
|
|
|
|
bkelly13 wrote: My conclusion: the template libraries are really cool and easy to use, but very inefficient.
Well this is not really an accurate statement, because it depends on the template library that you're using and it's implementation and whether your use fits in with the standard use that it was designed for. std::map containers are never going to be fast, so in your case, just about any other container would have been faster. All in all, you can likely make something that is just as fast or faster than any container because you can make it application specific (you know how much data you need and how it will be accessed), but that doesn't discount the use of template libraries.
|
|
|
|
|
When you're choosing a container choose a vector. They're (except for one case) as fast as an equivalent automatic array. Then if you find the interface or performance characteristics of something else works better you can change it later.
|
|
|
|
|
Well... although a dynamically growing vector will still be slower than a pre-allocated array. Although you can presize a vector as well but that would require you to know about the speed cost of dynamic allocation and how vectors allocate arrays internally. Guess what I'm getting at is... you have to know at least a little about your containers and how you're using them.
In summary, no free ride. 
|
|
|
|
|
Could anyone please help me to find why call to sort() is crashing at run-time in following code block:
string s = "Annnitttesrrh.";
vector<char> vecChar(s.begin(), s.end());
sort(vecChar.begin(), vecChar.end(), greater_equal<char>());
Am i missing something very basic ?
|
|
|
|
|
|
I think that equality don't work in sort. Why swap elements if they are equal?
|
|
|
|
|
Windows 7, Visual Studio 2008, C++, Console app
when writing an application that uses std::string this code does not compile:
void C_Client_WinAPI_TCP::Get_Host_Name( std::string * host_name )
{
std::size_t source_length = host_name->length();
std::size_t copy_length = m_host_name.copy( *host_name, source_length, 0 );
Getting the length is find. When doing the copy the error is:
1>e:\b\bryan_code\tcp_ip_win_api_01\client\c_client_winapi_tcp.cpp(22) : error C2664: 'std::basic_string<_Elem,_Traits,_Ax>::copy' : cannot convert parameter 1 from 'std::string' to 'char *'
It seems to me that when using a std::string method, as in dot copy, it should copy from a std::string to another. Why not?
Edit: And given the above method declaration what is the right way to accomplish this concept:
m_C_Client_WinAPI_TCP.Get_Host_Name( "home" );
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
modified 2-Oct-13 22:43pm.
|
|
|
|
|
The documentation[^] states that the destination parameter must be a pointer to a character array. Dereferencing a string does not return such a pointer.
In your second query, it would be better to declare the function as
void C_Client_WinAPI_TCP::Get_Host_Name(char* host_name);
That would allow you to pass a constant character string or a STL string to it.
Veni, vidi, abiit domum
|
|
|
|
|
When there is std::string declared in the prototype and in the caller, it seems to me I should be able to pass an argument of that type.
Follow up
std::string my_string;
char *p_char
p_char = *my_string;
This did not work for me. Understandable. What is the correct syntax for that concept?
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
|
|
|
|
|
|
>How to create iwebbrowser2 in protected mode? i have requirement that i have to create IE in protected mode and invoke one url
|
|
|
|
|
|
Ya i saw those links and created medium integrity process but it didn't work. i heard about COM broker process
Any idea about this? i didn't get any example code for creating broker process for IE protected mode
|
|
|
|
|
narasingubhanu wrote: Any idea about this? Sorry, no.
Veni, vidi, abiit domum
|
|
|
|
|
hi!!!!
how to modify the size of window , I modify the parameter of CDialog::onCreate(),but it does not work
|
|
|
|
|
You need to provide much more information. Saying "it does not work" tells us very little.
Veni, vidi, abiit domum
|
|
|
|
|
Windows 7, Visual Studio 2008, C++, MFC
Question:
How do we put a control in a group box?
Details:
A group box is dragged placed in the dialog and a control dropped on it. (Static text, check box, and button) When the group box is moved, the control stays put. I interpret this as indicating that the control was not added to the group. I have looked closely at the properties for the group box and the control and have not recognized anything that will accomplish this. What needs to be done to put the control in the group box.
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
|
|
|
|