|
Why can't you hook...???
I must say what a strange thread for VC++ forum...
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Hockey wrote:
what a strange thread for VC++ forum
you should hang out here more often! people are constantly asking stuff like this. how can i intercept all keystrokes/mouse actions? how can i prevent windows from moving? how can i intercept file I/O from other processes? how can i select menu items/click buttons/enter text/etc in other processes? how can i change text on windows in other processes?
i'm totally afraid of the kinds of apps they must be making.
WWJD? JWRTFM. found on /.
|
|
|
|
|
Actually I was referring to the exchange of words Anonymous and Tomasz had...it was kinda amuzing in this forum...considering most threads here are strictly technical. I thought it was funny...
Something for the lounge almost...
Cheers
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Is there any template class in STL that I can use to see if there are duplicates of a type? And, if so how many? I mean will any of these containers at least give you an error so that you know it is already in there?
Let's say I use an array or map or multimap, when I add a object of the same value, it notifies me so that I can keep track of how many duplicates I have. Would be nice if it did it automatically.
Example: I have a container of shorts. I add the values 1204, 1033, 1422, and then 1204 again. I don't really need 1204 added again, I just want some counter for 1204 to increment to 2. Later, I only want to print out containers that have duplicates and add the count of all the duplicates together? Actually, for now I don't even need the containers, I just need the count of duplicates.
Oh yeah, I guess I should say speed is sort of an issue here. I have to add up to 500 of these 4 digit octal code values within 4.6 secs mininmum. I don't want it to take long to find duplicates. Meaning, I don't want to have to do a for loop to find a duplicate, I'm hoping STL will do it for me via a hash or something. And everytime I add one of these values, I want to update the duplicate count immediately.
|
|
|
|
|
Set and map will both contain only one value the same, map will overwrite the old one if you put one in the same. You can check yourself if a value is there with any container by checking like this:
mycont::iterator it = find(mycont.begin(), mycont.end(), value);
if (it != mycont.end()) // then the value is there
If a container has a member find function ( such as list does, from memory ) you should use that instead
I believe the STL also has algorithms to count duplicate values. You could certainly write a functor to use with accumulate to count the value of adding duplicates. If you want something more specialised in how it handles duplicate values, that impliments reference counting, you may need to write it yourself. I have never used a hash_map ( which is a non-std container, but present in .NET and also in stpport ), but it's concievable that a good hash algorithm will fill each bucket with only entries of the same value.
Christian
We're just observing the seasonal migration from VB to VC. Most of these birds will be killed by predators or will die of hunger. Only the best will survive - Tomasz Sowinski 29-07-2002 ( on the number of newbie posters in the VC forum )
Cats, and most other animals apart from mad cows can write fully functional vb code. - Simon Walton - 6-Aug-2002
|
|
|
|
|
I'll look into the hash part of it. As I stated in reply to the next msg, for loops take time and that find() method will just iterate from beginning to end, not too bad since it will work for non-contiguous data but I think a hash would be better because it would immediately take me to that bucket without looking for it. The most time will be wasted looking to see if one exists and not so much in deleting or clearing all of the objects at every time interval. If I create an array or list of bucket items, then I can delete them every 4.6 secs time interval. And, recreate them as I process the next time interval. Thanks, Christian!
|
|
|
|
|
Well if speed is of much concern to you and you know the data - say you know the highest value you'll work with is 9999 - then this approach might work:
int arrItems[9999];
memset( arrItems, 0, sizeof( arrItems ) / sizeof( arrItems[0] ) );
for ( int i = 0; i < nNumItems; i++ )
{
int nValue = ...;
arrItems[nValue]++;
}
Would this work?
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
Well, it would work but not really what I'm looking for I considered doing this but I have to call the memset to clear the array every 4.6 secs which is one for loop (internally in machine code anyways). Then, I have to load the array, another for loop. Plus, if I only have 100 codes to enter in that time interval, I'm wasting time looping and putting empty slots. Probably, the max codes I'll have in a time interval is 500.
Actually, my data is values 0-3777 octal which is exactly 2048 bytes (2K). So, memory isn't a problem but speed checking whether one already exists in the array is. I think I will look into Christian's suggestion above, since I think a hash may be the fastest though I still will have to add elements and delete them every 4.6 seconds. However, the lookup will be tremendously faster.
|
|
|
|
|
JohnnyG wrote:
I don't really need 1204 added again, I just want some counter for 1204 to increment to 2.
Easiest way would be using map and its insert method which returns pair (details in any STL docs). First element of the pair is the iterator, second is true only if insertion took place. So if second is false, you have iterator ready for use, just increase the counter.
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
Tomasz Sowinski wrote:
First element of the pair is the iterator, second is true only if insertion took place.
You're saying that the it.second element is a bool with a value of false if the item has not been inserted ? I did not know that.
You've got a point though - using the reference count as the second element of the map is actually brilliant and obvious at the same time. Duh on me.
Christian
We're just observing the seasonal migration from VB to VC. Most of these birds will be killed by predators or will die of hunger. Only the best will survive - Tomasz Sowinski 29-07-2002 ( on the number of newbie posters in the VC forum )
Cats, and most other animals apart from mad cows can write fully functional vb code. - Simon Walton - 6-Aug-2002
|
|
|
|
|
Christian Graus wrote:
You're saying that the it.second element is a bool with a value of false if the item has not been inserted ?
Yeah. Both set and map have this insert overload. Discovering this was one of better moments in my STL-related activities
Now, if they provided us with simple case-insensitive comparisons on string
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
Tomasz Sowinski wrote:
Discovering this was one of better moments in my STL-related activities
really? the examples i looked at when i was using std::map all used the pair to test success, so i've known it as long as i've known map. i guess i just assumed everyone else learned from the same examples
-c
WWJD? JWRTFM. found on /.
|
|
|
|
|
Have you read Effective C++? It has several case-insensitive comparisons for stl.
Todd Smith
|
|
|
|
|
Todd Smith wrote:
Have you read Effective C++?
You probably mean 'Effective STL'
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
std::map<int, int> mymap;
mymap[1204] += 1;
mymap[1033] += 1;
mymap[1422] += 1;
etc.
Todd Smith
|
|
|
|
|
At what point does .second get initialised to 0 ?
Christian
We're just observing the seasonal migration from VB to VC. Most of these birds will be killed by predators or will die of hunger. Only the best will survive - Tomasz Sowinski 29-07-2002 ( on the number of newbie posters in the VC forum )
Cats, and most other animals apart from mad cows can write fully functional vb code. - Simon Walton - 6-Aug-2002
|
|
|
|
|
mymap[1024] calls insert(value_type(_Kv, _Ty()) where _kv and _Ty are int types. When you call int() it constucts an int initialized to 0. That's different than creating an int on the stack that doesn't get initialized. At least that's what happens on VC6 with MS-STL
Todd Smith
|
|
|
|
|
Can anyone tell me why when you add a new class or file it does not get added to VSS (like it was with VC6)? Were the developers too busy with the Excel Flight Simulator or what?
Michel
It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard
|
|
|
|
|
VSS = Visual Source Safe? Ewwww. Horrid. We switched to CVS because VSS used to be crap for multi-user projects (code shared by a team for example).
It's not like the movies. They fed us on little white lies.
|
|
|
|
|
I prefer not to automatically add a new class or file to source-safe. Only code that compiles should be added. Otherwise you end up breaking a build when somebody gets the latest code.
I'm suprised there isn't an option though.
Michael
Time flies like an arrow. Fruit flies like a banana
|
|
|
|
|
|
|
See Lounge.
Sleepy Jack the fire drill. Round and round and round and round.
|
|
|
|
|
I'm trying to use mmioOpen so a new file will be created (or truncated)
m_hFile = ::mmioOpen((LPSTR)(LPCTSTR)m_FileName,&mmioInfo, MMIO_CREATE|MMIO_WRITE|MMIO_EXCLUSIVE | MMIO_ALLOCBUF);
Sometimes mmioOpen fails. When I look in mmioInfo.wErrorRet, it's set to 257 (File not found). I can't understand why I get this error. Want to create the file, of course it doesn't exist.
But like I said sometimes this works, I haven't been able to figure out how to reproduce this.
Has anybody else run into this problem before?
|
|
|
|
|
Here's a little more info on the problem
I can create the file, record, and play from my app, but once I play the file from the explorer, then mmioOpen fails. I tried selecting a different file, but it still fails. I even tried deleting it, but it still fails. But once I hit F5, then my app will work again.
Any ideas why?
|
|
|
|