|
tbrake wrote: And do you anything aout ending threads quick ??
Not really, I let my threads manage their own lifetime. Much simpler and less prone to errors.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Exactly. If the thread does not end 'quickly' while doing its own work, then it is obviously making alot of synchronous calls, so then you need a redesign anyway, otherwise, it is just safest to wait.
In between making calls to do wok, the thread should check an 'exit' flag - a variable set to tru or soemthing. While 'waiting' for something to finish, it should use synchronization functions. You might have to use overlapped IO or look for asynchronous methods and API for things yo are doing synchronously. Also, try adjusting timeouts on operations.
If you know you are waiting, you can always tell user 'waiting for XXX to finish before shutting down' or some such message. In the case of Windows shutting down, well perhaps whatever you are waiting for will terminate, so your thread can finish up nicely anyway.
People that start writing code immediately are programmers (or hackers), people that ask questions first are Software Engineers - Graham Shanks
|
|
|
|
|
How to display the value of a variable in a MessageBox?
Thanks!
Vinceher
|
|
|
|
|
Put the value in a variable, and then pass that variable in as the second parameter.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
|
|
|
|
|
If you're using MFC (and every one around here seems to) use code something like this:
CString s;<br />
s.Format(_T("The number is: %d"), 42);<br />
AfxMessageBox(s);
Steve
|
|
|
|
|
Hi Stephen,
I'm using Visual C++ 2005 Express Edition.
I don't find the same function Format, parameters are differents...
Do you know how to fill this piece of code:
String^ s;
int i = 42;
s = ...
MessageBox::Show(s);
Thanks!
|
|
|
|
|
Looks like you using Managed C++ (which isn't really C++). This is really a dotNET question. I don't know much about dotNET but I think something like this will do it:
String^ s = String::Format(S"The number is {0}.", __box(42));
PS: If I was going to use dotNET (I'd have to be forced, at gun point) I'd use C#.
Steve
|
|
|
|
|
Or you could probably still be using the old-fashioned c-style:
char txt[100];
sprintf (txt,"The number is %d",nVar);
and then display that character array.
Good luck
William
|
|
|
|
|
Hello,
I am taking a Digital image watermarking in the wavelet transform domain for my graduation project .. can you please tell me what you know about it ? and what kind of techniques I should learn to achieve that .... thanks for listening
Luay Al-wesi
|
|
|
|
|
Just one question - What is Digital image watermarking in the wavelet transform domain?
Steve
|
|
|
|
|
|
I hope that subject captured what I'm trying to ask. An example would work best. I need to be able to sort an array of items based on multiple parameters the user passes in which are prioritized. For instance, take a list and:
First, sort by "Type"
Then, sort by "Name"
So, I need to be able to sort this list first by it's type. No problem, I've done that before. But then I need to sort the list again, but now by name. So I have to leave the types as they are, but sort the names belonging to each type in alphabetical order. Kind of a sublist within a list.
I have an idea of how to do it, as I've just described, but I'm looking for examples on how to handle this. It seems like it could get really out of hand...especially if I need to sort by a 3rd or more parameter. Maybe there is an easier way to handle this than I am thinking...? I hope!
Thanks,
|
|
|
|
|
See here.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
|
|
|
|
|
Thanks again for this link. In reading this, I also found the answer to a quirk I had noticed in using qsort() that is bothering me.
qsort() must be "unstable" according to this document. If for example I pass three items to this qsort, all of which have identical comparison fields (ie: the Type), then the list gets re-ordered anyway! I was trying to figure this out when each return from my sorting function was zero.
Any way to make qsort() "stable" so it won't change things if the comparisons are identical, or another function to use that would give me this result?
Thanks,
|
|
|
|
|
Gunn317 wrote: qsort() must be "unstable" according to this document.
True. It actually has to do with the algorithm itself, not necessarily the qsort() implementation.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
|
|
|
|
|
instead of just A > B, your test will now be something like:
((A.p1 > B.p1) ||
(A.p1 == B.p1 && A.p2 > B.p2))
in words: if the primary criteria match, test the secondary criteria. if not, you don't have to worry about the secondary.
that should be pretty easy to extend to multiple criteria.
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
Thanks for the info. The link and your sample code basically say the same thing.
Now I just have to figure out how to hook this up when I don't know what the user will choose to sort by. We have a listview with a bunch of columns and need the ability for the user to sort up to four of them at once and in priority order.
Currently with just sorting by one field, I have individual functions to pass to qsort to do this:
int SortByType(void *pElem1, void *pElem2);<br />
int SortByName(void *pElem1, void *pElem2);<br />
etc.
They each do a comparison their particular field. But if the user specifies more than one search criteria, I have to figure out how to get that to qsort()...any ideas?
Thanks again,
|
|
|
|
|
this might work: make an array of function pointers, one for each sort function that you'll use, in order. your qsort function would run down that array and call those comparators one at a time until it can tell for sure if A > B. you'll need to be able to test > and =.
it gets tricky to think about, but i get the feeling the code would be pretty small.
--
are you wedded to qsort ? if you can use std::vector, STL's std::stable_sort would make this job a lot easier. you would do something like:
std::stable_sort(data.begin(), data.end(), comparator1);
std::stable_sort(data.begin(), data.end(), comparator2);
std::stable_sort(data.begin(), data.end(), comparator3);
..etc
once per sort criteria, in order of importance.
that won't work
Cleek | Image Toolkits | Thumbnail maker
-- modified at 17:01 Thursday 23rd February, 2006
|
|
|
|
|
Yea, stuck with qsort(). We aren't able to use the STL currently for various reasons....
Thanks for the suggestion, sounds good! I'll work on that idea. So you are saying that in the function that qsort calls, is where I should run through the list of comparator functions?:
qsort( , , , &MySortFcn);<br />
<br />
int MySortFcn(void *p1, void *p2)<br />
{<br />
<br />
return value;<br />
}
|
|
|
|
|
yeah, that's what i was thinking. you call the next comparator any time you get an "A=B" result from the current one. otherwise, you'll know either Apx > Bpx or Apx < Bpx.
i've never tried it, but it feels like it should work.
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
Using qsort is old fashioned, you should be using STL - it's faster safer and more flexible. Here's how I'd do it:
----------
#include <iostream>
#include <algorithm>
#include <iterator>
using namespace std;
// Our data.
struct Blah
{
Blah(int Type, const char* pName) :
m_Type(Type), m_pName(pName)
{
}
int m_Type;
const char* m_pName;
};
// Print out a blah.
ostream& operator<<(ostream& s, const Blah& b)
{
s << "Type: " << b.m_Type << ", Name: \"" << b.m_pName << "\"";
return s;
}
// Sort functors.
struct SortByType
{
bool operator()(const Blah& l, const Blah& r) const
{
return l.m_Type < r.m_Type;
}
};
struct SortByName
{
bool operator()(const Blah& l, const Blah& r) const
{
return strcmp(l.m_pName, r.m_pName) < 0;
}
};
struct SortByTypeThenName
{
bool operator()(const Blah& l, const Blah& r) const
{
return SortByType()(l, r) | (!SortByType()(r, l) && SortByName()(l, r));
}
};
// The data.
Blah g_Blahs[] =
{
Blah(1, "George"), Blah(2, "Liam"), Blah(2, "Hank"),
Blah(0, "Abigail"), Blah(1, "Bob"), Blah(0, "Jessica"),
Blah(2, "Con"), Blah(1, "Kyle"), Blah(0, "Faye")
};
int main(int argc, char* argv[])
{
Blah* pBegin = &g_Blahs[0];
Blah* pEnd = &g_Blahs[sizeof(g_Blahs)/sizeof(g_Blahs[0])];
ostream_iterator<Blah> oi(cout, "\n");
// Sort by type.
cout << "Type:\n";
sort(pBegin, pEnd, SortByType());
copy(pBegin, pEnd, oi);
cout << "\n";
// Sort by name.
cout << "Name:\n";
sort(pBegin, pEnd, SortByName());
copy(pBegin, pEnd, oi);
cout << "\n";
// Sort by type and name.
cout << "Type and name:\n";
sort(pBegin, pEnd, SortByTypeThenName());
copy(pBegin, pEnd, oi);
cout << "\n";
return 0;
}
Steve
-- modified at 17:29 Thursday 23rd February, 2006
FIXED error in SortByTypeThenName.
|
|
|
|
|
Thanks for the great code example. Unfortunately, it's not entirely my code, but a team project and as such we aren't able to use STL in this project at this time. But I'll definately hold on to this example for future work.
|
|
|
|
|
Hi,
Anyone know if its possible to make Visual Studio 6.0 compile and link using a different compiler.
I like the VS 6.0 environment but I have to support many DOS apps in my work so I would like to be able to edit with visual studio and when I hit build I would like it to run my MSVC++ 1.5 compiler. I would want to do this on a project by project basis rather than all the time.
TIA
Tony
|
|
|
|
|
Create a utility project, add your .c or .cpp and .h files to it, and define a Custom Build step for each .c and .cpp file that compiles the files using a path to the v1.52 cl.exe.
Finally, in your Post Build step, define the linker command to link your app.
onwards and upwards...
|
|
|
|
|
Hi,
Great thanks
|
|
|
|
|