|
The size of collection C(X) can be so much big, that we might be interested in isolate the elements that are temporarily ignored, in another collection.
Further more, if all items are ignored, i am hoping that thread A blocks and not consume CPU for nothing.
Finally, the rate of calls to NotifyIncludeAllElements can be so much high, that if we make a shared lock with thread A there, then the performance of processing of A is greatly affected.
I tried to think about semaphore, signals, CAS operations, but came up with particular solution, you ca see it in this class I called AbstractDistributor : (Link to CodePlex)
http://pushframework.codeplex.com/SourceControl/changeset/view/98598#1909758[^]
When I think about the problem I can see many real world scenarios applicable to it. I am wondering if it is already solved in a good way.
Push Framework - now released !
http://www.pushframework.com
|
|
|
|
|
I have follow code :
m_sHex.Format(_T("FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF"));
char* p = NULL;
const int nDec = strtol(m_sHex, &p, 16);
sUDec.Format(_T("%u"), nDec);
sDec.Format(_T("%d"), nDec);
and sUDec is '65535' and sDec is '65535' ... I expected to see sUDec 4.294.967.295 and sDec -1 ... what I'm missing ?
|
|
|
|
|
strtol() will stop parsing at the first character that is not a hex digit. In your string this is the first space character.
When you remove the spaces from your string, all will be parsed. However, this will produce an out of range error (errno is set to ERANGE and strtol() returns LONG_MAX ). Because your string represents a 4 x 4 x 8 = 128 bit number.
To handle unsigned numbers, you may also use strtoul() .
|
|
|
|
|
You are right ! Thank you !
|
|
|
|
|
Flaviu2 wrote: m_sHex.Format(_T("FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF"));
Strange that you would use Format() rather than just assigning the value directly.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
I want to setup a default value if the string contain non haxa characters ...
|
|
|
|
|
I realize that, but since you are not actually doing any formatting, why not just use:
m_sHex = _T("FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF");
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
hello guys... I am trying to get the client area of my CListCtrl which shows vertical scroll bar when needed. The View is set to Report. Now, to prevent horizontal scrollbar, I am setting the width my column manually like this.
LVCOLUMN col;
CListCtrl->GetClientArea(&Rect1);
col.cx = (Rect1.right - Rect1.left) - 20;
But I want to set the width of my column based on something like this
CListCtrl->GetClientArea(&Rect1);
GetClientArea(ScrollBar of CListCtrl)
LVCOLUMN col;
col.cx = (Rect1.right - Rect1.left) - Width of Vertical ScrollBar;
But I don't have a clue how to get width of this built-in scrollbar OR how to get width of CListCtrl exluding ScrollBar? Thanks for any pointers.
This world is going to explode due to international politics, SOON.
|
|
|
|
|
GetClientRect() (not GetClientArea) returns the client area of the list control. The area of optional scroll bars is not included in the returned rectangle. So GetClientRect() returns different rectangles when scroll bars are present or not.
The size of the vertical scroll bar can be determined using GetSystemMetrics(SM_CXVSCROLL) . You may use this value upon list initialization (with empty list when no vertical scroll bar is shown) to preserve space for the scroll bar.
|
|
|
|
|
How can I provide one instance only for an object ? And here I'm not refer to CMyWinApp (one instance of an application), but a custom object ? It's an interview question ...
|
|
|
|
|
Hint: singleton.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Create a static count in the object and increment it in the constructor?
|
|
|
|
|
Ok, and when second instance is about to be executed, how can I stop it then ?
|
|
|
|
|
Use a get instance static member func to do that.
|
|
|
|
|
In header file:
class myUniqueClass {
private:
myUniqueClass(); myUniqueClass(const myUniqueClass&); static myUniqueClass* myUniqueInstance;
public:
static myUniqueClass* getInstance();
};
In cpp file:
myUniqueClass* myUniqueClass::myUniqueInstance = 0;
myUniqueClass::getInstance() {
if (myUniqueInstance == 0) {
myUniqueInstance = new myUniqueClass;
}
return myUniqueInstance;
}
Explanation:
The two private constructors prevent the uncontrolled creation of a new instance, or the copying of the one, valid instance. The getInstance function creates the one instance if necessary: as a member function it can use the private constructor.
|
|
|
|
|
And when I want to work with this object, I write :
myUniqueClass* pUniqueClass = myUniqueClass::GetInstance();
I'm right ? And what is happen when object goes out of scope ? I have memory leak ?
Stefan, I thank you very much !!
modified 6-Jul-12 6:38am.
|
|
|
|
|
Of course there is nothing to stop someone totally ignoring the GetInstance func and just creating their own, so it depends on your question, do you want to *force* users to have only one instance.
|
|
|
|
|
I think that is impossible to create a new instance of myUniqueClass because have private constructor ...
|
|
|
|
|
Good point.
|
|
|
|
|
Correct. getInstance is used to access the single object.
You are correct that the code above produces a memory leak. The problem is that the only way to avoid it is to create and destroy it from another singleton! In a windows application, you could implement that in your WinApp class. In a console program you could do it in main() .
Also, as Luc Pattyn mentioned in his response, my code can not prevent the creation of a second instance in multithreaded code: the creation of the instance (and the preceeding test of the pointer) has to be locked. However that is only a problem until the first instance is created, so you can solve this by creating the instance at the start of the program in main() or your WinApp class.
|
|
|
|
|
And what about thread safety? If you're unlucky two threads calling getInstance() at the same time may cause two objects being created. There are many ways to create a Singleton pattern, lots of the attempts are just wrong, only a few are correct without showing too much of a performance hit. Look at several articles on the subject here at CP, or elsewhere.
|
|
|
|
|
Yep, of course it needs lock protecting.
|
|
|
|
|
True. If you asked me how to implement a singleton in a multi-threaded environment, I might have thought of that
Oh well, maybe I'm just lucky that the things I work on involve virtually no multithreading at all!
|
|
|
|
|
This is an academic question - can standard MFC CSplitterWnd class be easily modified to allow floating static views?
There are few posts here about splitter window which do wonderful things, but not necessary easy to adopt.
Ideally I would like to have ability to select a view in sort-off pop-up fashion - make a duplicate and be able to move it around / re-size etc.
Any opinions are welcome.
Thanks for you time.
Vaclav
|
|
|
|
|
You can change the size of a splitter window by dragging the splitter bar and/or resizing its parent window. If you want a floating window then that is a different thing altogether. Perhaps you could explain some more of what you are trying to do.
|
|
|
|