|
I have a critical section that enables thread-safe reading from / writing to a CMapStringToString object.
The CMapStringToString could possibly grow in size to have around 200000 entries, where the 'key' is a string of <=6 characters, and the value will, on average, be around 300 characters.
Firstly, does anyone know how much memory a CMapStringToString object with 200000 entries with keys 6 characters long and values 300 characters long will actually use?
Secondly, when I call the Map's Lookup() function, will this start to take a long time to return if my map grows to this kind of size? Would this slowing down make it unsuitable to use inside a critical section which is probably being accessed by a different thread eg. 4 times per second?
Thanks for any thoughts anyone might have,
Matt
|
|
|
|
|
Firstly, you should set your initial block size to a large number to create more hash buckets, thereby separating your strings into smaller sets and decreasing the search time.
If you need to access this many elements so frequently via multiple threads, I would suggest that you create a higher level hash table (of smaller size) that would contain locks (critical sections) and pointers to individual sections (hash tables) of the entire data set. By doing this, you will get higher concurrency at the cost of more memory usage. This way, you would lock only a section of the set that you were interested in, rather than the entire set.
onwards and upwards...
|
|
|
|
|
I have a couple of questions about using the CCriticalSection class. Firstly, is there any difference between the way the critical section works by using it in the following two manners:
1)
CCriticalSection blocker;
blocker.Lock();
// Do something
blocker.Unlock();
2)
CCriticalSection blocker;
CSingleLock singleLock(&blocker);
singleLock.Lock();
// Do something
singleLock.Unlock();
Also, am I correct in saying that using either of these methods, no thread will time-out when waiting for the critical section to become free - they will just wait until it's they're turn to use the code?
Any comments would be much appreciated,
Thanks,
Matt
|
|
|
|
|
Hi Matt
The CCriticalSection class is the lock that is accessed from more than 1 thread and ensures that if 1 thread has called CCriticalSection::Lock (not having called CCriticalSection::Unlock yet), another thread's call to CCriticalSection::Lock will block - effectively suspending the second thread until the first calls CCriticalSection::Unlock.
The CSingleLock class is simply a smart-pointer style helper class that acts on the CSyncObject that is passed in with it's constructor - in essence, it just calls the CSyncObject::Lock in it's constructor and CSyncObject::Unlock in the destructor. That way you can have the SyncObject's Unlock method automatically called when the CSingleLock local variable goes out-of-scope....
but an example says a thousand words;
CCriticalSection csGlobal; // global variable, or such..
void Thread1()
{
CSingleLock lock(&csGlobal);
// do stuff
}
void Thread2()
{
CSingleLock lock(&csGlobal);
// do stuff
}
So you can see that the smart-pointer style local CSingleLock instances really just capitalise on the C++ destructor to help you remember to call csGlobal.Unlock. Without the CSingleLock, you could end up writing (faulty) code like this;
void Thread3()
{
csGlobal.Lock();
// do some stuff
if (bFailed)
return; // !!!! didn't call csGlobal.Unlock();
// do more stuff
csGlobal.Unlock();
}
Lastly, the explicit Lock/Unlock methods on CSingleLock is really if you can't wait for the destructor, and need to Unlock and possibly Lock again.
I hope this makes sense.
Martin
|
|
|
|
|
If I use a class which has 10 methods and 10 attributes, but I only access/use 5 methods and 5 attributes from that class in my program, will the resultant executable also include code/data for the other 5 methods and attributes ?
I suppose I'm asking if the linker is clever enough to discard unused functions and data.
PS. I'm using Visual C++ 6.
|
|
|
|
|
At one point in time very long ago, I seem to remember that the linker would remove unused code from EXEs but not from DLLs. How it works today is unknown to me. Is this causing an issue with you?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
It's not a big problem. I'm new to C++ having come from a C background. With the availablility of all the classes on CodeProject (and other sites), it's easy to just drop in classes to facilitate easier programming. However, if I only use a small fraction of the functions in the different classes, then I'm thinking that my application will end up being unnecessarily bloated with code that never gets executed and data members that never get accessed.
I suppose can test it easily enough by creating a test app and then seeing if the code size is larger or the same size when I access more class member functions/variables. I was just curious if anyone knew and had a bit more info on how it works.
|
|
|
|
|
With the exception of a few isolated cases (e.g., EPROM with KBytes of RAM), this exercise would be a complete waste of time with little to no benefit/payback. Most of the time, this "smaller is better" idea is fostered by incorrectly-interpreted information. What you should be concentrating on is how big the program's data is.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
|
HI!!!
i'm doing my Msc... and want to do a project.. develop any application in MFC/C++... can you please suggest some good topics.. for the project - THANKS! -V.G
|
|
|
|
|
any particular personal interest ?
does it have to be in any particual field ? graphics, database, computational, multimedia, web-related ?
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
hi!! sorry for being so late.. actually i'm just a beginer..but the project has to be good.. can u suggest any good project for beginners...we r a teamof five.
|
|
|
|
|
How can you be a beginner if you are doing your Msc (I assume this is a computer-related Master's degree)?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Yes, I'm doing MSC... but am new to the subject i.e Programming in windows
|
|
|
|
|
What about my suggestion here?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Great that you have embarked on using MFC to do your project . But the fact is there has to be a core technology that MFC can revolve around . you could use MFC almost anywhere there is any engineering / business
here is a quick list that i could think about
Database related
Networking related
OS related
Hardware related - serial port communication
testing related
The sky is the limit
Engineering is the effort !
|
|
|
|
|
Have you asked for input from your project/thesis advisor?
In any case, read this article, especially the paragraphs from jury member Richard Morris.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Hello:
I am developing a library that must automatically detect new files in a certain directory and then process them.
If a user creates a file (such a text one) using any program in the directory and he edits and saves the file without closing, no action has to be taken. The action has to wait until we are sure the file edition is complete and file is closed.
How can I check wether the file has been opened by any process in the local machine or even remotely?
Is it possible to get a notification when the file is closed by the user?
I should work out the problem using no MFCs.
Any help will be really welcomed.
Jose M.
Just re-entering programming world after a long break.
|
|
|
|
|
look for CFile::shareExclusive in MSDN
regards
Rajesh
|
|
|
|
|
|
Can I manually insert an activeX into to an existing activeX?
|
|
|
|
|
I’m about to implement multi-select in my derived CTreeCtrl class. I have problem with the default expand behaviour of the CTreeCtrl.
1. I only want the tree to expand when left clicking (not right clicking) it
2. I only want the tree to expand when clicking the plus-sign (not the item text)
All tips are welcomed!!
_____________________________
...and justice for all
APe
|
|
|
|
|
Hi
In order to help, I've built a CTreeView-derived view to play with and have found;
Right-clicking doesn't expand tree items in my test app (??) - might be the version of common controls I'm using, but more importantly, I've overridden the OnLButtonDown member in the view, like so;
void CTreeTestView::OnLButtonDown(UINT nFlags, CPoint pnt)
{
UINT uFlags = 0;
HTREEITEM hSelectedItem = GetTreeCtrl().HitTest(pnt, &uFlags);
switch (uFlags)
{
case TVHT_ONITEMLABEL:
//mk GetTreeCtrl().SelectItem(hSelectedItem);
return;
}
_RPT3(_CRT_WARN, "## LButtonDown (x=%d, y=%d) returns %x\n", pnt.x, pnt.y, uFlags);
CTreeView::OnLButtonDown(nFlags, pnt);
}
which then gobbles the click whenever you click on the label, and everything else, like clicking on the expand button (plus/minus sign) works in the default way.
The bottom-line;
you can override the mouse clicks for your tree control in the standard way (WM_LBUTTONDOWN, et al message handlers) - where you can then use the CTreeCtrl::HitTest member to determine on which part of the tree the click occured, and then take the appropriate action.
In this fashion, you might even be able to customise right-clicks, etc.
HTH
Martin
PS: You might find that since the tree control's behaviour is more for black-box use than customization, you'll probably have to re-implement a lot of the basics over again - you'll have to see how much the effort's worth it.
|
|
|
|
|
What to say...
- A PREFECT ANSWER!!
Thanks!!
_____________________________
...and justice for all
APe
|
|
|
|
|
I am doing a program whereby Im creating an application that extracts information from MS Access Database and displays it out in Visual C++6.
I am using the ODBC Database method.
What I am trying to do is to input and also display Chinese characters in VC++6. The information in my MS Access Database are also in Chinese.
So far what I have only comes out as "???" (question marks!)
Yes I have installed MFC unicode libraries
I have also defined _UNICODE.
I hope the kind and clever people here would sincerely help me.
Thanks so much.
|
|
|
|