|
-
Jan 31st, 2003, 08:07 AM
#1
Thread Starter
Fanatic Member
2 questions - pure api and namespaces
first question is i'm trying to write a program the "pure api" way and i've got everything working but its taking all the CPUs time.
2nd, im assisting in a computer science 4 class and the teacher is new (he's just learning C++ with the students) and he wants to know about namespaces. So i told him what they're for and that you need something to the affect of using namespace std; for all the new header files and that its recommended that you use the new header files, but he still wants to know why? im not sure if i understand what he's asking, maybe he wants to know why microsoft made new headers for things and put everything in a standard namespace?
The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.
-
Jan 31st, 2003, 06:25 PM
#2
Frenzied Member
Re: 2 questions - pure api and namespaces
Originally posted by DNA7433
first question is i'm trying to write a program the "pure api" way and i've got everything working but its taking all the CPUs time.
2nd, im assisting in a computer science 4 class and the teacher is new (he's just learning C++ with the students) and he wants to know about namespaces. So i told him what they're for and that you need something to the affect of using namespace std; for all the new header files and that its recommended that you use the new header files, but he still wants to know why? im not sure if i understand what he's asking, maybe he wants to know why microsoft made new headers for things and put everything in a standard namespace?
I thought the new guy was supposed to be good 
Anyway, It wasnt Microsoft that decided to create new headers. It was the standards committee. The older headers (<iostream.h>, etc) are only there for compatibility's sake. The new headers all lose the ".h", and everything within them is inside the std namespace. Namespaces allow for several codebases to be sued within the same application. For instance, If I was writing a game, and needed a vector class to hold my object's position, without namespaces, id have to call it something other then "vector" for the code to even compile. With the name space, I have my "vector", but I can also use the vector container, because it is within the std namespace (std::vector).
To use the namespace, you CAN use "using namespace <name>", but it is recommented that you only use the parts you need, ie:
Code:
#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;
...
cout << "blah" << endl;
string x("Hello");
...
For smaller programs, this isnt a big deal, but when your code base gets huge, you dont want your global namespace to be cluttered.
As for your first question, do you have a Message pump?
Code:
If(GetMessage(...))
{
TranslateMessage(...);
DispatchMessage(...));
}
Z.
-
Jan 31st, 2003, 06:34 PM
#3
Thread Starter
Fanatic Member
hey dan, long time no see
the new teacher supposedly has a background in vb and java and worked on government stuff. and what you just told me there was practically the same exact thing i told him, i even showed him an example of using namespaces and he still wondered why. I'm not really sure what he's asking. Another year, another new batch of students...they're coding habits are horrible and they don't know how to fix simple problems, but i guess thats why i'm there.
the api thing was almost exactly what you had given me last year
this is the message loop with win XP home, and it just takes all the CPU capacity.
Code:
while(GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.
-
Jan 31st, 2003, 07:00 PM
#4
Frenzied Member
Im sure you remember me cringing when I saw something like this:
Code:
void PushStack(stack_t* s, int v)
{
...
=).
The amount of actual API code I write is pitifully small in proportion to the amount of programming I do... Im not going to be much help in that area... I could care less if my code takes up all the CPU... games are supposed to =).
As for the namespace thing... Im not sure what else to tell you... its there for code cleanliness, and modularity.
Z.
-
Jan 31st, 2003, 07:36 PM
#5
Fanatic Member
Use PeekMessage instead of GetMessage.
-
Feb 6th, 2003, 08:03 AM
#6
Thread Starter
Fanatic Member
I've tried PeekMessage and GetMessage, and using Sleep(0) and nothing seems to work. I use other people's code and it seems to work fine and i can't get mine to work! It all looks the same except some people choose different style when setting up the window class.
The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.
-
Feb 6th, 2003, 12:11 PM
#7
Frenzied Member
-
Feb 6th, 2003, 03:07 PM
#8
Member
Put Sleep(2) somewhere in the code. It should work
Death is always smiling down on us, the only thing we can do is smile back
-
Feb 6th, 2003, 03:19 PM
#9
Thread Starter
Fanatic Member
both of those work perfectly...i just can't understand i need those an no one else does? do you want me to post the two programs im talking about?
oh and zaei, i got in a sort of arguement over the debugger with the CS teacher today. this kid was getting an access violation and i told him to hit debug and go through the context menu and it was coming from inside an apstring. the teacher was standing there and he starts telling him to insert cout everywhere to see where it crashes and then comment and uncomment things. all the while im trying to politely say why don't you try the debugger and he keeps defending his methods and finally he just stops responding to me and later he dragged me outside and told me i really pissed him off in there. I think he has an ego problem and doesn't like that i know more about C++. Then he told me to write up a lesson on the debugger and told me to teach the class.
The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.
-
Feb 6th, 2003, 03:19 PM
#10
Monday Morning Lunatic
Cool.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 6th, 2003, 07:21 PM
#11
Addicted Member
DNA , what grade are you in??
-
Feb 6th, 2003, 08:14 PM
#12
Member
my powers tell me he's a senior at his highshcool (probably grade 12)
Death is always smiling down on us, the only thing we can do is smile back
-
Feb 6th, 2003, 09:07 PM
#13
Thread Starter
Fanatic Member
you have really amazing powers
The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.
-
Feb 6th, 2003, 10:19 PM
#14
Frenzied Member
Originally posted by DNA7433
both of those work perfectly...i just can't understand i need those an no one else does? do you want me to post the two programs im talking about?
oh and zaei, i got in a sort of arguement over the debugger with the CS teacher today. this kid was getting an access violation and i told him to hit debug and go through the context menu and it was coming from inside an apstring. the teacher was standing there and he starts telling him to insert cout everywhere to see where it crashes and then comment and uncomment things. all the while im trying to politely say why don't you try the debugger and he keeps defending his methods and finally he just stops responding to me and later he dragged me outside and told me i really pissed him off in there. I think he has an ego problem and doesn't like that i know more about C++. Then he told me to write up a lesson on the debugger and told me to teach the class.
What a ******. Makes me want to teach. Dear God help us...
Z.
-
Feb 8th, 2003, 06:55 PM
#15
As for the CPU thing, use the GetMessage loop you have and make sure you respond to the WM_PAINT message in some way. The minimum response is
Code:
case WM_PAINT:
ValidateRect(hwnd, NULL);
return 0;
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 8th, 2003, 07:28 PM
#16
Thread Starter
Fanatic Member
The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.
-
Feb 10th, 2003, 11:18 AM
#17
yay gay
Originally posted by Zaei
What a ******. Makes me want to teach. Dear God help us...
Z.
unfortunalty my last 2 computer's teachers were also some dumb ones..and they think they know a lot and got pissed when i say things aren't the way they say they are
\m/  \m/
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|