Results 1 to 17 of 17

Thread: 2 questions - pure api and namespaces

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    837

    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.

  2. #2
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710

    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.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    837
    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.

  4. #4
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    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.

  5. #5
    Fanatic Member petrus's Avatar
    Join Date
    May 2002
    Location
    pBytes[sizeof(pBytes)/2]
    Posts
    553
    Use PeekMessage instead of GetMessage.
    ICQ: 128716725

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    837
    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.

  7. #7
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Maybe WaitMesasge().

    Z.

  8. #8
    Member
    Join Date
    Dec 2002
    Location
    Miami,FL
    Posts
    34
    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

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    837
    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.

  10. #10
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  11. #11
    Addicted Member Osiris's Avatar
    Join Date
    Oct 2000
    Location
    Dimension Hole
    Posts
    142
    DNA , what grade are you in??
    ؊Ϯϊ

  12. #12
    Member
    Join Date
    Dec 2002
    Location
    Miami,FL
    Posts
    34
    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

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    837
    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.

  14. #14
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    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.

  15. #15
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    837
    thanks again cornedbee
    The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.

  17. #17
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    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
  •  



Click Here to Expand Forum to Full Width