|
typical 10, 100 not unusual - admitted, that's not too much.
but typical access is over two maps, and comparison is case-insensitive (which adds up)
But maybe you're right, I should implement it with a simple list, and see how fast it is.
One day I might find it quite amusing how touching tongues make life so confusing Anne Clark again [sighist]
|
|
|
|
|
Why does the lookup need to be based on string comparison? If you just want fast lookup preserving the order of insertion, try using this class as the key of your map this:
class seq_string
{
public:
seq_string(const char *str):str(str),count(total_count++){}
seq_string(const std::string& str):str(str),count(total_count++){}
seq_string(const seq_string& r):str(str),count(total_count++){}
operator const char *()const{return str.c_str();}
operator const std::string&()const{return str;}
bool operator <(const seq_string& r)const{return count<r.count;}
private:
std::string str;
unsigned int count;
static unsigned int total_count;
};
...
unsigned int seq_string::total_count=0;
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
thanks for the suggestion, but I need both string-based lookup, and iteration in (temporal) order of insertion (although your class keeps the info, it would about O(n*n) to actually iterate in "sorted by count" order)
I'll go with the list<> implementation and a linear search, and make some speed comparisons.
[edit]
some interesting results (not all to much surprising)
times only for lookup
with <= 10 strings, the list is faster, for 25 strings it's list is about factor 2 slower, factor 3 for 50. (map looses early for creation of a std::string from literal when doing the lookup, and additional comparison for equality)
Having said that, With 25 strings in a list I get ca. 200.000 accesses / second on my 1.3GHz box, not astonishing, but fast enough for most uses.
All this is just lookup, map insertion is of course much slower due to additional comparisons (and I might be stuck with thousands of inserts and just a few lookups), so list implementation is "perfect enough"
One day I might find it quite amusing how touching tongues make life so confusing Anne Clark again [sighist]
|
|
|
|
|
Hi all,
I will write a ATL server exe programm with outgoing event interface and connection points for some client programs. For this solution I haven't found any good samples, so my first implementation is not working
My event interface is derived from IUnknown and
only a interface. In the client I use the normal
Advice methode to make the sink interface working, but I cannot see any events.
The second problem, I must fire some events from a worker thread in a third party Dll or using a timer. Here I have a error
! fire event failed (0x8001010e).
Is here a simpler solution than using
CoMarshalInterThreadInterfaceInStream and a worker thread ?
I hope some COM Guru has a answer
|
|
|
|
|
I am getting an error in the cout statement??
What should I do??
C:\My Documents\lakshmi\cplusplus\stldeque\test.cpp(28) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::deque<class std::basic_string<char,struct="" std::char_traits<char="">,class std::allocator<char>
main() {
string alpha[4] = {"nava", "dana", "lakshmi", "pavi"};
deque<string> ids1;
for (int i =0; i<4; i++) {
ids1.push_back(alpha[i]);
}
typedef deque<string>::iterator id_iter1;
for (id_iter1 i1 = ids1.begin(); i1 != ids1.end(); i1++ )
cout << *i1 << "\n";
}
|
|
|
|
|
i changed the iterator initialzation, and changed the order of the include files, and the code worked...
#include <deque>
#include <iostream>
#include <string>
using namespace std;
main() {
string alpha[4] = {"nava", "dana", "lakshmi", "pavi"};
deque<string> ids1;
for (int i =0; i<4; i++) {
ids1.push_back(alpha[i]);
}
deque<string>::iterator id_iter1 = ids1.begin();
for (; id_iter1 != ids1.end(); id_iter1++ )
cout << *id_iter1 << "\n";
}
|
|
|
|
|
How can we make a windows service in ATL.And how can we add methods/functions to it ??
|
|
|
|
|
The easiest is to run Visual Studio Wizard and select ATL service. You'll get all necessary code to register and start the service. If your methods/functions are COM-based, then just insert COM objects (using ATL Wizard). If not, you'll have to do it yourself. (My advice: base your communication protocol with service on COM, it's really easy to implement).
Vagif Abilov
MCP (Visual C++)
Oslo, Norway
If you're in a war, instead of throwing a hand grenade at the enemy, throw one of those small pumpkins. Maybe it'll make everyone think how stupid war is, and while they are thinking, you can throw a real grenade at them.
Jack Handey, Deep Thoughts
|
|
|
|
|
I have an object that derives from CWindowImpl and I would like to make it a drop target. Apparently adding IDropTarget isn't enough and I would like to know what else is required for me to add drag and drop.
My scenario is that I have a TreeView and would like to click on one of the items and drag it onto a custom view and fire off a behaviour based on the item that has been dragged.
Cheers,
Clint
|
|
|
|
|
|
I have created a WTL Form based APP using the WTL 7.0 Wizard. I insert the ActiveX Control "Sysmon" (System Monitor), having passed the LIBID in the .Init call. I call ::CoInitialize(NULL), since ::CoInitializeEx(NULL, COINIT_MULTITHREADED) will not work.
Now, the System Monitor AX control shows up on the dialog form, but will absolutely not work (the counter bar does not move!).
Then I tried to create the AX using CAxWindow and then the Create call on this. Same result.
I tried to set up proper message routing in the PreTranslateMessage functions, but still I cannot get the performance monitor to move (start counting).
However, creating a MFC form based app, and inseting the same AX on the form, this works like a charm.
What is the issues with WTL? Can anyboy help on this?
Thanks in Advance,
obt
|
|
|
|
|
Love to see the following MFC Property Sheet Wizard ported to WTL framework.
Look at http://www.codeguru.com/propertysheet/PropSheet_Wizard.shtml
|
|
|
|
|
Hi'
I'm writing an ATL component to manage RAS connections.
I've got all my Async Dial stuff operating coreectly, and I've now introduced threads to enable multiple operations to all occur.
Now when I watch the Open Handle Count, I notice it just Keeps growing. The documentation says I should CloseHandle on any threads I create, but wheree is the safest place to do so.
in the destructor?
In the End of the Thread function itself (i'm passing it a This which contains a member variable of the hThread)
Please help... I'm experiencing weird errors on the machine and I'm pretty sure it's related to this.
Thanks so much.
Paul Farry
|
|
|
|
|
If you dont need the handle then close it immidiatly after CreateThread()
/Magnus
- I don't necessarily agree with everything I say
|
|
|
|
|
|
Can anyone explain why i have to use a namespace specifier in the code below?
#include <set>
using std::set;
class myclass
{
...
set<CString,strcmpfn> myset;
...
myfunc()
{
...
set<CString, strcmpfn>::iterator it = myset.find(szPath);
...
}
};
/Magnus
- I don't necessarily agree with everything I say
|
|
|
|
|
|
Hi,
I tried to make a std::map of classes like this:
<br />
class A<br />
{ ... };<br />
<br />
typedef map<long, A> AMAP;<br />
As soon as I began experimenting I realized that things were not as simple as I hoped. For example, this code:
<br />
AMAP amap;<br />
amap[10];<br />
Will generate 1 call to A's default constructor and two calls to A's copy constructor. Before I continue experimenting to find the best way to make a map of classes I'd like to hear some advice from people who have already tried this sort of thing. Two specific questions I have are:
1) Is it advisable to have a map of classes?
2) Does anyone know the best way to acheive this?
Any other advice/comments/talk about the subject will be appriciated.
P.S. My class will not only consist of built-in types, but will also have pointers.
Thanks,
James
Drinking In The Sun
Forgot Password?
|
|
|
|
|
One solution I found was to use pointers instead:
typedef map<long, a="" *=""> AMAP;
amap[10] = new A;
This negates the cost of default and copy constructors. However, it does mean that you then have to manage the deletion of the pointers yourself, as empyting the map will just remove them from the map, not from memory. Unfortunatley, auto_ptr does not work here!
I would be interested to see if there are any other solutions, as it seems to be very costly to use anything other than basic types in a container
|
|
|
|
|
I agree that using new and storing pointers is the way to go for any of the STL containers if you don't want the default ctor's and dtor's called unneccessarily. I'd prefer to delete them myself, however the Boost shared_pointer should work fine here, not that I've tried such a thing.
Re. your original question. I guess it depends why you need a collection (multiple instances) of the class in the first place.
Neville Franks, Author of ED for Windows. www.getsoft.com
|
|
|
|
|
I have in fact resorted to pointers for now, which I agree is the best way to go overall.
I would like to find out the best way to have a collection of classes without resorting to pointers, even if it worse than using pointers. I do not have any particular reason why I need a collection of the class - this is purley research.
Thanks,
James
Drinking In The Sun
Forgot Password?
|
|
|
|
|
both the default CTor and the 2 copies come from the insertion of a default value, if the requested key is not found. So if you use:
tmap::iterator it = map.find(key);
if (it != map.end())
else
Frankly, map is my single most used STL class, and I find myself always coding around the operator[].
The two copies come from
1) creating a temp pair<const key,="" value=""> that is passed to insert, and
2) copying the pair<const key,="" value=""> into the map
(frankly, a good library design would not need one of the copies)
You can ignore that if you have classes with "cheap" Copy-CTor's for default-constructed classes, and do complex construction after inserting a default, like this:
value & v = map[10];
v.ReadDataFromHugeFileAndKeepIt();
the same is true for classes that hold System resources (like HANDLE's that are closed in the DTor) and have no acceptable copy contructor.
Peter
One day I might find it quite amusing how touching tongues make life so confusing Anne Clark again [sighist]
|
|
|
|
|
|
Has someone experience with greta?
void example()
{
string sText="er.r.n.i.e";
match_results results;
rpattern pat("(\\w+\\.)+");
match_results::backref_type brip = pat.match(sText, results);
for(int i=0;i
|
|
|
|
|
Idefix wrote:
I think the parser works but how can i get the single items? Is that possible?
Try:
rpattern pat("{\\w+}\\.");
iterate through your string and extract the text matching the {} tag. Note that I don't know Greta, but this is what you would do with a typical Regex.
Idefix wrote:
Where can I find more documention and information?
Have you tried: http://research.microsoft.com/projects/greta/gretauserguide.htm[^]
Neville Franks, Author of ED for Windows. www.getsoft.com
|
|
|
|