|
Yeah, this occured to me in the shower a half hour ago. Does that make me a total nerd ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Nah. I think that most developers are not nerds, even if they think about IT related stuff when they are taking a shower! Other people think about their work all the time. They even talk about it during dinner. I bet that most developers don't do that, since we know that nobody is going to understand what we will say about 95% of the time... So the real nerds (in terms of being obsessed with their work and talk about nothing else) is everybody else!
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Well, I thought of a faster way again on the way to work this morning...
void ConvertLongToIPAddress( long nLong,
unsigned char& ch0,
unsigned char& ch1,
unsigned char& ch2,
unsigned char& ch3) // lowest part
{
unsigned char * pIP = (unsigned char *) & nLong;
ch0 = pIP[3];
ch1 = pIP[2];
ch2 = pIP[1];
ch3 = pIP[0];
}
I seem to recall a Dilbert cartoon where he has to hand in a timesheet and says 'the time I spent doing nothing in meetings is marked as work, and the time I spent designing circuits in the shower is not on there'.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Christian Graus wrote:
Well, I thought of a faster way again on the way to work this morning...
LOL! Where do you get some rest?
I give up here. I might be able to prduce a slightly better result in assembly, but I want get back to something I left behind...
Christian Graus wrote:
I seem to recall a Dilbert cartoon where he has to hand in a timesheet and says 'the time I spent doing nothing in meetings is marked as work, and the time I spent designing circuits in the shower is not on there'.
I just love the Dilbert cartoons! Don't you?
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Bob Stanneveld wrote:
Where do you get some rest?
About five hours a night. Except when I have sticky programming problems, then I dream about them. Not that I'm obsessive or anything.
Bob Stanneveld wrote:
I just love the Dilbert cartoons! Don't you?
Yeah, they rule. NEver had a bad boss, so I can't relate, but I still love it. The books are even better, especially 'The Dilbert Future'. If you don't have it, get it. It's REALLY funny
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Christian Graus wrote:
Yeah, they rule. NEver had a bad boss, so I can't relate, but I still love it. The books are even better, especially 'The Dilbert Future'. If you don't have it, get it. It's REALLY funny
Í don't have it... yet!
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Not totally but close.
It used to be a running joke between me and my boss. I would always come up with my best ideas in the shower so one day after several instances of this he said, "you know, we should pay your water bill."
|
|
|
|
|
*grin* Now that would be nice. I often wake up with the answer to my programming questions, I wonder what bill i could give my boss in that instance ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
There's also:
in_addr ia;
ia.S_un.S_addr = 16951488;
TRACE(_T("%u.%u.%u.%u\n"),
ia.S_un.S_un_b.s_b4,
ia.S_un.S_un_b.s_b3,
ia.S_un.S_un_b.s_b2,
ia.S_un.S_un_b.s_b1);
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
That's just what I was thinking. I had forgotten it was already built though.
|
|
|
|
|
I try to use EnumProcesses on Windows 2000/VC++6.0, but it need psapi.h & psapi.lib but they are wroking on windows NT?!!
|
|
|
|
|
Install the Platform SDK.
I don't think those two files came with the Visual Studio 6.0 distribution.
Make your Visual Studio development environment search into the platform SDK include and library folder ahead of the one delivered with Visul Studio 6.0.
|
|
|
|
|
Hello, i'm apoligize in advanced for this question, but all the explanations from the msdn, and such, that i got for it are extreamly confusing.
I would like to know what a Vector is and how i can use it.
thankz!
|
|
|
|
|
Which vector class are you talking about? For example the Standard Template Library provides an implementation of a vector class. The vector class can be used to store any number of elements of any type. For example you can have an array of integers but that is restricted to hold only as many items as you specify at the beginning as opposed to a vector in which you can store variable amount of data.
Here's some example code
<br />
std::vector<int> BunchOfNumbers;<br />
BunchOfNumbers.push_back(1);<br />
BunchOfNumbers.push_back(32);<br />
<br />
for (int j = 0; j < BunchOfNumbers.size(); j++)<br />
{<br />
printf("%d", BunchOfNumbers[j]);<br />
}<br />
|
|
|
|
|
A vector is a form of array. Its can be added to on the fly and grows as needed, managing the memory allocation as you go. You can also access it like an array. Its there to make life easiser.
e.g.
#include <vector>
using namespace std;
void main()
{
vector<int> a;
int i = 2;
a.push_back(5 * i);
a.push_back(3 * i);
printf("size is [%d], first is [%d], second is [%d]", a.size(), a[0], a[1]\n");
}
Outputs:
"Size is 2, first is 10, second is 6
There is more you can do, but you can find that out yourself.
|
|
|
|
|
To add to the other explanations - what makes vector cool is that it shares a common interface with other container classes through a thing called an iterator. While you can use array notation to access a vectors members, you can use iterators to step through them also, and the STL contains a lot of algorithms that take iterators and work on containers to organise and process their contents.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Whooop! Looks like they forgot to preview.
Variable array of intergers:
std::vector<int> int_array;
Most used methods:
back(): returns a reference to the last element.
pop_back(): remove the last element.
operator[]: returns a refernce a specific element.
push_back(element): adds an element to the end of array.
begin(): returns iterator of first element.
end(): returns interactor just passed the last element.
capacity(): the number of elements it can hold before it has to reallocate storage.
size(): the number of elements currently stored.
erase(...): removes 1 or more elements from array.
clear(): removes all elements from array.
empty(): (size() < 1)
reserve(n): reserves extra storage space (capacity); if you know approximately how many elements you need to store, then reserving that amount will reduce the number of reallocations required (thus increasing the speed of insertion and reducing memory fragmentaion).
typedef std::vector<int> int_array_type;
int_array_type int_array;
for( int i=0; i<int_array.size(); ++i )
{
if( some_int_value == int_array[i] )
}
int_array_type::const_iterator i = int_array.begin();
for( ; i != int_array.end(); ++i )
{
if( some_int_value == *i )
}
Hope that helps.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
I have a CList containing objects. I want to know if I can use a vector on this CLIst or do I have to use vector<myojb> instead of CList.
The issue here is that I need a container that I can easily add/remove objects to, test to see if its empty and sometimes apply a function to that object.
This is my first time thinking of using vectors, but I like the for_each option instead of using a 'typical' for loop using CList.GetNext(pos).
ANy ideas?
|
|
|
|
|
vectors and the rest of the standard C++ containers rock. i haven't used an MFC container in new code in years.
you might also look at std::list, if you really need a list and not an array - subtle difference that might not be important for your use.
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
You're comparing apples and oranges for two reasons
1/ MFC containers are crap, you should be using the STL
2/ A CList is a list of linked nodes, faster for random insertions, slower for random access. You should look at the list class, unless you have a reason to go to an array ( fast for random lookup, slow for random insertions ). Then vector is what you want.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi,
I am kind of new to multi threading.I am doing a project in vc++ win32.
I am using two threads - one for reading from port and another for writing to the port.
But when I execute...sometimes the flow gets mixed up..I want the read thread to go first and when it is done I want to start the write thread and then again read thread...I dont want start one thread while other is going on..
How do I accompilish this..I want have a state m/c kind of..but have no idea how to do one..
pls help...thanks in advance..
|
|
|
|
|
You have two threads. Can't each one wait on an Event set by the other?
The read thread waits to do work until the write thread sets an event. The write thread waits for the Read thread to set an event. Each one sets the even the other is waiting for at the end of its own processing, signaling it is safe for the other to take over. I would think they would flop back and forth as you desire. It should not deadlock, I don't think, because neither one is waiting on both of the events to be signaled. You could always put a timeout in one of the threads that should have higher priority, in the case they are both idle waiting for 'the other guy' to set the event.
It would also be ideal if the port could set an event or some signel to let you know data was available for reading. I would think your process is the one repsonsible for any writing that occurs.
|
|
|
|
|
Ann66 wrote:
I dont want start one thread while other is going on
This leads me to believe you don't need a multi-threaded design. A single thread that sequentially reads and writes should work.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
UNLESS the application is doing something ELSE while it is sitting there waiting for a read or write. I suspect they need at least two threads. The program's primary thread and a single secondary thread for the IO. It seems they read, and want to process data and then write, or something like that. I tend to agree that maybe a separate thread is not required to separate the reading from the writing, but I would put the IO in a separate thread so it can wait to receive data, or else not tie up rest of application performing synchronous writes or whatever it is they are doing.
|
|
|
|
|
Blake Miller wrote:
I tend to agree that maybe a separate thread is not required to separate the reading from the writing, but I would put the IO in a separate thread...
Yes, that's what I meant.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|