Thread: C++++

  1. #31
    booyakasha
    Join Date
    Nov 2002
    Posts
    208
    Originally posted by Shadow12345
    What do you mean real time programming
    Real time programming means that certain things have to be done by a certain time or they become pointless.

    For example imagine you are writing a DVD software program.
    Lets say you are computing the images to put on screen, and then when the correct time comes up you send the image to the monitor.
    Now lets say that your processor is too slow and you reach a time when you have to put an image to the screen, but you having finished processing/creating the image yet. A real-time system has to know that it missed its chance and therefore should stop decoding the image and move on to work on other frames. Real time programs also have to predict wheter it can finish a task on time, and if they can't finish it on time, they shouldn't even start working on it ( because they will end up making eveything afterwards later ). So if your processor is too slow it may only be getting up 3 out of four frames, but the video will still be playing at the correct speed.

    If the system wasn't real time it would just wait for the image to be done and then show it, so the user would see their movie running in slower and slower motion ( which is not acceptable ).

    An example of something that isn't real-time is your compiler. It doesn't stop if it's taking too long. It just keeps going, until it finishes.

    Real time program is not better then regular execution, it's just for different purposes then standard execution. In reality Real-time programs are less efficient then non-real-time programs, because the time spent on the overhead of scheduling means that less actual work is being done. But, like i said, it is nessecary for certain applications

  2. #32
    Registered User
    Join Date
    Dec 2002
    Posts
    29
    There are a few measures you can take to ensure that only one instance of a class can be created...one way is reference counting...

  3. #33
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Static type checking of variable length argument lists.

  4. #34
    Shadow12345
    Guest
    I'll have to read up on singletons because I haven't thus far

  5. #35
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Along with static type checking on variable length argument lists (if this is even possible) How about a jazzed up NULL? NULL a la Scott Meyers:
    Code:
    const class
    { 
    public:
        templace<class T> operator T*() const { return 0; }
        template<class C, class T> operator T C::*() const { return 0; }
    private:
        void operator &() const;
    } NULL;
    Hey! This goes hand in hand with the whole singleton thing too.

  6. #36
    Neoseeker's master master2000's Avatar
    Join Date
    Dec 2002
    Posts
    101
    sorry i was out so long my cpu brok. but im planing to make a code writer so c++ wont be so tough other wise with all these problems it makes nerds look cool

  7. #37
    Shadow12345
    Guest
    I feel kind of stupid for asking, but I don't really know what's going on here. I guess I'm not as l33t as I thought But I guess I feel stupider (is that even a real word?) for not asking

    Code:
    const class
    { 
    public:
        templace<class T> operator T*() const { return 0; }
        template<class C, class T> operator T C::*() const { return 0; }
    private:
        void operator &() const;
    } NULL;
    Umm yeah, can someone fill in Shadow12345 on what all that stuff means? What does the operator T* do? operator T C::*? operator &?

    EDIT: and yes I think I understand that that is a 'NULL' class meaning it isn't supposed to do anything, but if it WAS functional, what would those methods do? Thanks
    Last edited by Shadow12345; 01-16-2003 at 05:56 PM.

  8. #38
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Don't worry, I had plenty of trouble understanding it when I first saw it.
    and yes I think I understand that that is a 'NULL' class meaning it isn't supposed to do anything
    Oh, it's quite functional, let me explain.

    Suppose you overload a function like this:
    int encode(int num);
    int encode(char *num);

    What happens when you pass 0? Of course, the integral version is called. What happens when you pass NULL? With a casual glance, probably not what you'd expect. So you can't pass a NULL pointer to encode().

    It's a good rule of thumb NOT to overload on pointer and integral types, but what happens if this slips through? Probably bugs!

    So, back to NULL. You either need to do something like this static_cast<char*>(NULL) to pass a NULL pointer to the function. But that's ugly, so make an object which encompasses this behavior.

    template<class T> operator T*() const { return 0; }
    This is an implicit conversion operator for every type T. So if we pass encode(NULL), we actually get an implicit conversion to a char * passed off to the function.

    void operator&() const;
    This prevents people from taking the "address" of NULL. I'm pretty sure operator& is one of those implicitly generated member functions, so you need to explicitly disallow the use of it by declaring it private. Also, no defintion is provided-- this is to prevent friends from taking the address as well (I don't know why NULL would ever have any friends... anyway), if a friend attempts to do this you'll get a linker error.

    template<class C, class T> operator T C::*() const { return 0; }
    This deals with pointers to member functions... it's still a little cloudy to me, so i'll quote straight from the book.
    "As long as we're making it possible to convert NULL to any type of pointer, we should handle pointers to members, too. That calls for a second member template, one to convert 0 to type T C::* ("pointer to member of type T in class C" for all classes C and all types T.

Popular pages Recent additions subscribe to a feed