|
Christian Graus wrote:
I suspect you are in hell. I don't see how you can easily do what you want. What you might try is create two console apps, and enable MFC in one ( I believe you can ). Do a diff of the two projects and see what has changed, and that might give you some ideas.
Playing games?
You cruel cruel man, but I like it.
|
|
|
|
|
A few hints :
- compiler options
use multithreaded run-time (/MD) (or /MDd if you are in Debug)
add the _AFXDLL compiler switch
- linker options
replace /subsystem:console with /subsystem:windows
- target type
open the .dsp file, and replace "(x86) Console Application 0x0103" with "(x86) Application 0x0101"
Back to real work : D-26.
|
|
|
|
|
|
I *was* using ostringstream as a member in a message construction class for a communication protocol. The app in question is a message format converter, that handles a few thousand messages per second on average and peaks can be in 10s of thousands per second.
The problem:
time_t t1, t2;
time(&t1);
for(unsigned long index = 0; index < 1000000; ++index)
{
ostringstream s;
}
time(&t2);
printf("%d\n", t2-t1);
takes 5 seconds to complete, ie, 5microseconds just to init the ostringstream.
Is there something that I am doing wrong?
Now, I replaced the ostringstream with a char buffer[MAX_SIZE] and is using sprintf and lstrcat instead. The CPU utilization at peak reduced from around 50% to 12 - 13%.
The times of ostringstream drops to 1 second for the above loop, if I use the Singlethreaded library instead of multithreaded.
I do not have a specific question, but I would guess that one should use stringstream very carefully in a very performance critical part of a multithreaded program.
Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
Exactly. I have no problems using standard C string because I am VERY VERY careful. When I want to be even EXTRA careful, I use vsnprintf which is overrun safe.
I use STL a lot. But when it comes to time critical, I am always going back to code written specifically for the job.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
I used sprintf, only because the largest message size is already known and anything larger than that is discarded.
modified 29-Aug-18 21:01pm.
|
|
|
|
|
I hate to agree with Tim on this ( hi, Tim ), but it's obvious that a generic solution such as ostringstream is simply not going to be optimised for the sort of heavy use you're asking of it. If it's only initialising, you can keep an ostringstream member and use str("") to clear it, but overall, 10,000 hits a second to me is time to go as low level as possible.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
Hehehe
I know I really over state my position a LOT. But most of the time that is all I am trying to say. I just want people to be open to alternative ways of doing things. Understand the problem and the available solutions and it is hard to go wrong.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Tim Smith wrote:
I know I really over state my position a LOT.
Yeah, not like me at all. Oh, wait.... :P
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
LOL - and I really mean it too.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
actually, LOSLISTC - Laughed out so loud I scared the cats.
I looked down and they were both looking up... "What the hell is wrong with you????"
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Christian Graus wrote:
use str("") to clear it,
reduced from 5 ms to 4 ms. Anyway, cannot compete with a char buffer. As Tim and you pointed out, my obsession with using STL in all situations caused this problem. I should have realized (as I have now) earlier that a high efficiency loop requires optimization and not generic classes.
In fact, initially I was having another thread of discussion with Tim about hash_map (because i did not suspect ostringstream, until I profiled it). Actually hash_map works great and the hash function which I copied from the CMapStringToString in MFC gives me virtually 0 collissions for my data set.
Anyway, I learned that I should not assume anything about a problem.
Thanks a lot for the insight you guys give. I have definitely become a much better programmer and designer with the interactions that I have at CP.
Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
Can somebody show me how do I implement in my view the event on item expanding using a CTreeViewCtrl derived class.
Thanks
|
|
|
|
|
VC++ would have been a better forum for this question. More people who may know the answer to this question hang out there.
modified 29-Aug-18 21:01pm.
|
|
|
|
|
The main reason of asking this in this forum, was because I found that the message handling of the events is handled in diferent ways. So the way is handled in MFC projects is not the same as in WTL projects.
So I rather be asking this to people of this forum because my project is an WTL/ATL project.
|
|
|
|
|
hellooo ppl.. long time since I ventured to codeproject..
anyway... I've been facing this problem..
I have an activex dll written in vb that exposes a few methods..like
public function fn1(byval x a integer, byval y as integer) as integer
fn1 = x + y
end function
I want to use this in my mfc/ atl project... I used #import to import the dll and as vb exposes a smart pointer to my interface.. I used it to call my method... but I get a runtime error when the pointer is being created...
I would like to know the low-down on using components developed in vb.. is it possible to use them without using automation ..if yes how do I go about creating a custom no automation iterface in vb!
thks guys
One more addition to the addiction of coding!
If you want a helping hand, you'll find one at the end of your arm.
|
|
|
|
|
How exactly are you creating the instance of your COM object?
Are you (error checking and handling omitted):
_MyObjectPtr pPtr("MyProject.MyObject");
pPtr->fn1(...);
or
_MyObjectPtr pPtr;
pPtr.CreateInstance(__uuidof(_MyObject));
pPtr->fn1(...);
"The greatest danger to humanity is humanity without an open mind." - Ian Mariano
http://www.ian-space.com/
|
|
|
|
|
Ok, given IID I can load the library....
And If I am given the path -> LoadTypeLib(Path) loads the library (perfect).
Is there any way when given IID discover dll, or exe server path/filename????
Thanks,
Brian
|
|
|
|
|
Never mind QueryPathOfRegTypeLib
|
|
|
|
|
What's the best way to stream a container?
inline std::ostream& operator<<(std::ostream& out, const MyClass& s)
{
return out << s.m_SomeVar;
}
MyClass myClass;
std::cout << myClass;
how do I do the same but with a vector of MyClass?
std::vector<MyClass> myClasses;
std::cout << myClasses;
use for_each maybe?
std::for_each(m_PopProfiles.begin(), m_PopProfiles.end(), Something<std::cout>()); ??
Todd Smith
|
|
|
|
|
I found this on a web site. I am sure someone with a clue can post a better solution:
copy (l.begin(), l.end(), ostream_iterator(cout, ""));
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Just what I needed. Thanks!
Todd Smith
|
|
|
|
|
Hi.
I would like to debug a simple algorithm that does not work using an STL solution. The solution works via iteration.
std::list<unsigned int=""> theList;
for (unsigned int i = 0; i < 10; ++i)
theList.push_back(i);
// theList should now contain 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9.
// Remove "6" from the list.
// Assume that iTheList is an iterator that points to element with value 6.
theList.erase(iTheList);
// After erase() theList should now contain 0, 1, 2, 3, 4, 5, 7, 8, and 9.
Okay. Everything above works as designed. Now I would like to decrement everything bigger or equal to "6," thus make theList hold 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. Here is the iterative solution.
-----
// Given iTheList points to theList.begin().
while (*iTheList <= 6)
++iTheList
// Now decrement until end of theList.
while (*iTheList != theList.end()
{
*iTheList = *iTheList - 1;
++iTheList;
}
-----
The iterative solution above works perfect.
I would like to implement a more efficient and elegant solution. Here is one solution using STL algorithms. However, it does not work correctly.
-----
std::for_each(std::find_if(theList.begin(), theList.end(), std::bind2nd(std::greater<>, 6)), theList.end(), std::bind2nd(std::minus<>, 1));
-----
The STL solution above does not work. The logic and syntec seem to be valid.
Is there a logic or syntec misunderstanding in the STL solution? I looked over the function objects and function adapter. They are valid.
Thanks,
KUphryn
|
|
|
|
|
Why are you trying to replace simple code with a god awful stream of unreadable syntax that you have to work hard to actually get to work? That isn't programming, that is STL masturbation.
Stick with the simple solution. Of course, these days that isn't the politically correct answer.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
I see your point.
Kuphryn
|
|
|
|