unsure how to implement MFC CArray with class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • WW

    #16
    Re: [OT, link] unsure how to implement MFC CArray with class

    Mike Stenzler wrote:
    [SNIP][color=blue]
    > BTW- who is "us"? Do you speak for others?[/color]

    Take a chill pill. Or change to decaf.

    --
    WW aka Attila


    Comment

    • Fao, Sean

      #17
      Re: [OT, link] unsure how to implement MFC CArray with class

      "Mike Stenzler" <mstenzler@ssar is.com> wrote in message
      news:3F7C2084.6 CFB2DB7@ssaris. com...

      [..]
      [color=blue]
      > Having 2 small children and job deadline
      > pressures to meet, I usually don't have the luxury of poring through doco[/color]
      and[color=blue]
      > "teaching myself" when I'm trying to implement a technique that's new to[/color]
      me.[color=blue]
      > That's when I rely on asking others who have the knowledge I need - I[/color]
      thought[color=blue]
      > that was a big component of what Usenet was all about - people sharing
      > knowlege.[/color]

      Well you're in luck because nobody else here has kids, jobs or deadlines to
      worry about.


      Comment

      • Default User

        #18
        Re: [OT, link] unsure how to implement MFC CArray with class

        Mike Stenzler wrote:[color=blue]
        >
        > Jonathan Mcdougall wrote:
        >
        > [snip]
        >[color=green]
        > > shows us that you don't want to look by yourself, which is not a good[/color]
        >
        > [snip]
        >[color=green]
        > > Jonathan[/color]
        >
        > BTW- who is "us"? Do you speak for others?[/color]


        I agree with both Jonathan and WW.


        You are behaving like a jackass. There are plenty of people helping
        others all the time here.

        You come in, don't bother lurking or checking the FAQ for topicality,
        then insult the entire group by stating that they refuse to help people.
        As pointed out, there are a number of tutorials regarding std::vector
        and the other standard container classes.



        Brian Rodenborn

        Comment

        • Mike Stenzler

          #19
          Re: [OT, link] unsure how to implement MFC CArray with class



          "Fao, Sean" wrote:[color=blue]
          >
          > "Mike Stenzler" <mstenzler@ssar is.com> wrote in message
          > news:3F7C2084.6 CFB2DB7@ssaris. com...
          >
          > [..]
          >[color=green]
          > > Having 2 small children and job deadline
          > > pressures to meet, I usually don't have the luxury of poring through doco[/color]
          > and[color=green]
          > > "teaching myself" when I'm trying to implement a technique that's new to[/color]
          > me.[color=green]
          > > That's when I rely on asking others who have the knowledge I need - I[/color]
          > thought[color=green]
          > > that was a big component of what Usenet was all about - people sharing
          > > knowlege.[/color]
          >
          > Well you're in luck because nobody else here has kids, jobs or deadlines to
          > worry about.[/color]

          Well, I don't feel lucky... :)

          Comment

          • Jonathan Mcdougall

            #20
            Re: [OT, link] unsure how to implement MFC CArray with class

            > > > 2. If my question is on-topic I can expect to be told to RTFM[color=blue][color=green]
            > >
            > > Yes, if your question was already answered or if your askings are
            > > very general. Something like "how do I use std::vector" shows
            > > us that you don't want to look by yourself, which is not a good
            > > thing. Get a book or something.[/color]
            >
            > read my question or the whole thread or something -[/color]

            FYI, I've been here since the start and I answered your questions.
            Look on Google, it archives all posts, maybe you missed one. Note
            that it may take up to 8h for a post to appear there.
            [color=blue][color=green][color=darkred]
            > > >as this
            > > > group isn't about helping people.[/color]
            > >
            > > Please.[/color]
            >
            > please what?[/color]

            This kind of statement ("as this group isn't about helping people.")
            is useless and only makes everybody angry. Please, try to
            stay polite and think about what you write.
            [color=blue]
            > [snip]
            >[color=green]
            > > But never, _never_ ask a question implying that
            > > you don't have the time to do something so you're asking others.[/color]
            >
            > This is obviosly a terrible crime. Possibly a felony. Please add this
            > very important requirement to the FAQ so I or others like me who
            > actually have to do things in life won't make this terrible mistake
            > again.[/color]

            It is.



            [color=blue][color=green]
            > > You will almost be banned from this place.[/color]
            >
            > Ahh, BANISHMENT!! Can you send a couple of guys to drag me away in a
            > straightjacket instead? I really like it when they twist my arms back,
            > and the smell of crisp white cotton...[/color]

            That was to be taken with a smile. I think irony does not travel well
            by internet.
            [color=blue]
            > Since I've managed to insult 2 fully qualified C++ experts on this[/color]

            Two, I don`t know, but you did not _insult_ me for sure, you just
            look like a troll right now, that's it. It takes quite a big troll for
            me to feel insulted.
            [color=blue]
            > newsgroup by asking a simple question, I'll make it easy for you and
            > banish myself.[/color]

            By banishment, I was not talking literaly.
            [color=blue][color=green]
            > > Please, RTFM :)[/color]
            >
            > Yes Sir, right away sir.[/color]

            That was a joke, noticed the smiley?
            [color=blue]
            > Anyway, thanks for your moment of helpfulness - the code snippet you
            > incuded previously compiles and works and has made it clear that
            > std::vector is an avenue I can pursue instead of CArray. I did have a
            > couple of follow-on questions about the efficiency of multiple function
            > calls (v.push_back()) to load this vector/array and why you included
            > pop.back()[/color]

            Well go for it and stop saying these things!! This discussion is *useless*,
            people are here to help other people, not to talk like that. So please,
            and this applies to *everyone* including me, shut the fuck up, let's
            forget that thread, and let's start a new one about std::vectors, ok ?
            I'm getting tired of that shit.

            <snipped>


            Jonathan


            Comment

            • Mike Wahler

              #21
              Re: [OT, link] unsure how to implement MFC CArray with class

              "Mike Stenzler" <mstenzler@ssar is.com> wrote in message
              news:3F7C400B.C 105A7AE@ssaris. com...[color=blue]
              > All UNREASONABLE questions will be instantly rejected and the supplicant
              > suitably punished.
              >
              > Mike aka Senior Vice President & Chief Technology Officer of a company
              > that manages (very well thankyou) close to a billion (with a B) USD - of
              > course I have absolutely no qualifications for the job, they just took
              > pity on me once they realized what a tough time I had programming.[/color]

              [sigh]

              *PLONK*

              -Mike



              Comment

              • Mike Stenzler

                #22
                Re: [OT, link] unsure how to implement MFC CArray with class



                Default User wrote:[color=blue]
                >
                > Mike Stenzler wrote:[color=green]
                > >
                > > Jonathan Mcdougall wrote:
                > >
                > > [snip]
                > >[color=darkred]
                > > > shows us that you don't want to look by yourself, which is not a good[/color]
                > >
                > > [snip]
                > >[color=darkred]
                > > > Jonathan[/color]
                > >
                > > BTW- who is "us"? Do you speak for others?[/color]
                >
                > I agree with both Jonathan and WW.
                >
                > You are behaving like a jackass. There are plenty of people helping
                > others all the time here.[/color]

                That is an argumentum ad hominem. In case you don't know what that is
                please RTFM. Additionally, I didn't know jackasses can type. I think you
                are behaving like an orangutan.
                [color=blue]
                > You come in, don't bother lurking or checking the FAQ for topicality,[/color]

                You're absolutely right - but I already admitted to that transgression
                and apologized. Then I moved on and asked a question that WAS topical.
                [color=blue]
                > then insult the entire group by stating that they refuse to help people.[/color]

                Read the thread. Didn't happen. I never said a word about the behaviour
                of anyone except those I was in direct communication with. That comment
                (see below) was a sarcastic comment directed at one single individual
                who took it upon himself to "manage" the newsgroup.
                [color=blue]
                > 2. If my question is on-topic I can expect to be told to RTFM as this group isn't about helping people.[/color]

                I didn't ask for a tutorial, I didn't ask for 4 chapters of text, I
                didn't ask to understand the entire subject, I didn't ask to get into
                this little pissing match - I just asked how to use std::vector to
                implement an array of classes. I DEFINITELY did not SAY ANYTHING about
                the newsgroup as a whole and the netiquette of it's posters. As evidence
                that this question was not so overly broad as to be unanswerable except
                by reading several chapters of a book - Jonathan answered my question in
                about 20 lines of code and gave me the info I was looking for.
                [color=blue]
                > As pointed out, there are a number of tutorials regarding std::vector
                > and the other standard container classes.[/color]

                Yes, it was previously mentioned.

                Mike Stenzler

                Comment

                • WW

                  #23
                  Re: [OT, link] unsure how to implement MFC CArray with class

                  Mike Wahler wrote:[color=blue]
                  > [sigh]
                  >
                  > *PLONK*[/color]

                  Et tu, Mike? ;-)

                  --
                  WW aka Attila


                  Comment

                  • WW

                    #24
                    Re: [OT, link] unsure how to implement MFC CArray with class

                    TROLL ALERT!


                    Comment

                    • Mike Stenzler

                      #25
                      Re: [OT, link] unsure how to implement MFC CArray with class

                      Jonathon-


                      Jonathan Mcdougall wrote:
                      [snip]
                      [color=blue]
                      > FYI, I've been here since the start and I answered your questions.[/color]

                      I know you did. I acknowledged that. My thanks were genuine. I just
                      don't think my question was that broad to get painted with the RTFM
                      brush. You proved that by answering it with like maybe 20 lines of code.
                      Yes, I need to do some reading to use this further. But Jeez, lighten up
                      on people.
                      [color=blue]
                      > Look on Google, it archives all posts, maybe you missed one. Note
                      > that it may take up to 8h for a post to appear there.[/color]

                      I didn't miss any posts, I can see the whole thread here in my news
                      reader. I DID miss a few smiley's of yours and probably wouldn't have
                      given YOU any sass if I'd seen them.
                      [color=blue]
                      >[color=green][color=darkred]
                      > > > >as this
                      > > > > group isn't about helping people.
                      > > >
                      > > > Please.[/color]
                      > >
                      > > please what?[/color]
                      >
                      > This kind of statement ("as this group isn't about helping people.")
                      > is useless and only makes everybody angry. Please, try to
                      > stay polite and think about what you write.[/color]

                      Is calling me a jackass, polite? (Not you - Brian Rodenborn aka
                      Default_User).

                      That statement was made as a sarcastic comment on Atilla's behaviour as
                      newsgroup nazi. I just don't like being shit upon, especially by a herd.

                      [color=blue]
                      >[color=green]
                      > > [snip]
                      > >[color=darkred]
                      > > > But never, _never_ ask a question implying that
                      > > > you don't have the time to do something so you're asking others.[/color]
                      > >
                      > > This is obviosly a terrible crime. Possibly a felony. Please add this
                      > > very important requirement to the FAQ so I or others like me who
                      > > actually have to do things in life won't make this terrible mistake
                      > > again.[/color]
                      >
                      > It is.
                      >
                      > http://www.parashift.com/c++-faq-lite/how-to-post.html[/color]

                      I looked but I'm not sure I see that in the faq.

                      [snip]
                      [color=blue]
                      > That was to be taken with a smile. I think irony does not travel well
                      > by internet.[/color]


                      You're right. It doesn't. I missed the smiley, missed 2 of 'em I think.
                      Most seemed to have missed my ironies.

                      [color=blue][color=green]
                      > > Since I've managed to insult 2 fully qualified C++ experts on this[/color][/color]

                      [snip]

                      [color=blue]
                      > That was a joke, noticed the smiley?[/color]

                      Missed it. Sorry.
                      [color=blue]
                      >[color=green]
                      > > Anyway, thanks for your moment of helpfulness - the code snippet you
                      > > incuded previously compiles and works and has made it clear that
                      > > std::vector is an avenue I can pursue instead of CArray. I did have a
                      > > couple of follow-on questions about the efficiency of multiple function
                      > > calls (v.push_back()) to load this vector/array and why you included
                      > > pop.back()[/color]
                      >
                      > Well go for it and stop saying these things!! This discussion is *useless*,
                      > people are here to help other people, not to talk like that. So please,
                      > and this applies to *everyone* including me, shut the fuck up, let's
                      > forget that thread, and let's start a new one about std::vectors, ok ?
                      > I'm getting tired of that shit.
                      >
                      > <snipped>
                      >
                      > Jonathan[/color]

                      OK, I'll bite (that's how I got into several people's kill files to
                      begin with) :)

                      it seems to me that using this std::vector class to instantiate an array
                      of class objects isn't too efficient. In C you declare (and allocate
                      memory for) an array in one shot, then use very efficient direct
                      addressing (subscript notation, not ptr) to access the array members.
                      Unfortunately, the array is not dynamically resizeable, so limited in
                      usage (from my perspective) - I prefer linked lists, usually when I use
                      an array it's strictly for efficiency. In VB of course, arrays are
                      resizeable (redim). The MFC CArray class creates an empty array that is
                      then settable to a number of elements using CArray::SetSize (). So in a
                      possible implementation for me I could instantiate an array, set it to
                      some reasonable size, then fetch data into it and if the reasonable size
                      is exceeded I could use CArray::SetAtGr ow() or CArray::Add() to grow the
                      array record by record. Microsoft claims that using CArray::GetAt() &
                      CArray::SetAt() to access the array members (each in this case a class)
                      is just as efficient as the direct addressing of C language.

                      Now, I DID RTFM as far as the a.pop_back() that you had included in your
                      snippet, I'm not sure I understand why, but id does solve the problem I
                      immediately saw of an empty element at .last. I still see (under a
                      debugger) an empty at .end - not sure if this is a problem. Here's where
                      a RTFM comment is warranted. What I'm curious about now is I don't see
                      any way to batch allocate an array (vector) of a certain size - it's
                      certainly clear that using your method will work, but it grows the array
                      a record at a time - that seems inefficient compared to the MFC
                      implementation and certainly compared to raw C arrays. Am I missing
                      something? Or id this just a tradeoff situation?

                      Mike

                      Comment

                      • Buster

                        #26
                        Re: [OT, link] unsure how to implement MFC CArray with class


                        "Mike Stenzler" <mstenzler@ssar is.com> wrote
                        [color=blue]
                        > What I'm curious about now is I don't see
                        > any way to batch allocate an array (vector) of a certain size[/color]

                        For default-initialized elements,
                        std::vector <name_of_type > name_of_vector (size_of_vector );

                        For copy-initialized elements, I forget which way round it goes
                        (but it's in the FM :)

                        Good luck and best regards,
                        Buster.


                        Comment

                        • Mike Stenzler

                          #27
                          Re: [OT, link] unsure ... thanks!

                          Ahh! Thanks.
                          Mike

                          Buster wrote:[color=blue]
                          >
                          > "Mike Stenzler" <mstenzler@ssar is.com> wrote
                          >[color=green]
                          > > What I'm curious about now is I don't see
                          > > any way to batch allocate an array (vector) of a certain size[/color]
                          >
                          > For default-initialized elements,
                          > std::vector <name_of_type > name_of_vector (size_of_vector );
                          >
                          > For copy-initialized elements, I forget which way round it goes
                          > (but it's in the FM :)
                          >
                          > Good luck and best regards,
                          > Buster.[/color]

                          Comment

                          • WW

                            #28
                            Re: [OT, link] unsure how to implement MFC CArray with class

                            Mike Stenzler wrote:[color=blue]
                            > That statement was made as a sarcastic comment on Atilla's behaviour
                            > as newsgroup nazi. I just don't like being shit upon, especially by a
                            > herd.[/color]

                            You don't need to be shit upon. You smell troll without it. And I have to
                            inform you that I do not take lightly to be called a nazy. You have crossed
                            the line.

                            --
                            WW aka Attila


                            Comment

                            • Default User

                              #29
                              Re: [OT, link] unsure how to implement MFC CArray with class

                              Mike Stenzler wrote:
                              [color=blue][color=green]
                              > > You are behaving like a jackass. There are plenty of people helping
                              > > others all the time here.[/color]
                              >
                              > That is an argumentum ad hominem.[/color]

                              What are you talking about? I was making an observation, not debating a
                              topic.



                              Brian Rodenborn

                              Comment

                              • Jonathan Mcdougall

                                #30
                                Re: [OT, link] unsure how to implement MFC CArray with class

                                > it seems to me that using this std::vector class to instantiate an array[color=blue]
                                > of class objects isn't too efficient.[/color]

                                For sure arrays are more efficient than std::vector, since it is a
                                class with some book-keeping. But imho, better safe than sorry.
                                [color=blue]
                                >In C you declare (and allocate
                                > memory for) an array in one shot,[/color]

                                std::vector<int > v(10); // 10 element vector
                                [color=blue]
                                >then use very efficient direct
                                > addressing (subscript notation, not ptr)[/color]

                                v[0]

                                is best you can have. In the best case, it only redirects to the
                                array (assuming the internal representation _is_ an array).

                                The member function at() gives checked access to the vector :

                                try
                                {
                                v.at(10) = 50;
                                }
                                catch(std::out_ of_range)
                                {
                                // ...
                                }
                                [color=blue]
                                >to access the array members.
                                > Unfortunately, the array is not dynamically resizeable, so limited in
                                > usage (from my perspective) - I prefer linked lists, usually when I use
                                > an array it's strictly for efficiency.[/color]

                                In that case, check out std::list.

                                [ot]
                                Usually, std::vector's internal representation is an array which is
                                copied around and resized when full. std::list is usually a linked
                                list. But aside from the speed constraints, this is implementation
                                defined.
                                [/ot]
                                [color=blue]
                                >In VB of course, arrays are
                                > resizeable (redim).[/color]

                                In C++ too, but you have got to do that manually.
                                [color=blue]
                                >The MFC CArray class creates an empty array that is
                                > then settable to a number of elements using CArray::SetSize ().[/color]

                                std::vector::re serve() is the closest match. It reserves memory
                                to avoid reallocation.

                                For example :

                                std::vector<int > v(10);

                                this creates a vector of 10 elements. It is correct to do

                                v[0] = 5;
                                v[1] = 54;
                                ...
                                v[9] = 21;

                                If you want to enlarge the vector, you *must* *add* elements
                                via push_back() or insert().

                                v.push_back(12) ;

                                Since the vector had only 10 elements, it must grow (create a new
                                array, copy the data, delete the old one). It could grow by one,
                                but this would not be very efficient, so it grows by a given
                                factor, let's say 2. So now our std::vector has 20 elements for
                                which memory is reserved, but only *11* accessible.

                                If you know you have a lot of inserts or push_back to do, you
                                can reserve the memory to avoid reallocation :

                                v.reserve(100);

                                Here, the memory is reserved for 100 elements. You can now add
                                100 elements with no reallocation.

                                You must understand the difference between capacity (with reserve())
                                and size (with push_back and insert). reserve() does not create
                                element, insert and push_back do.
                                [color=blue]
                                >So in a
                                > possible implementation for me I could instantiate an array, set it to
                                > some reasonable size, then fetch data into it and if the reasonable size
                                > is exceeded I could use CArray::SetAtGr ow() or CArray::Add() to grow the
                                > array record by record.[/color]

                                std::vector::pu sh_back() adds an element at the end of the vector and
                                grows it if needed. std::vector::in sert() inserts an element at the
                                given position and grows it if needed.
                                [color=blue]
                                >Microsoft claims that using CArray::GetAt() &
                                > CArray::SetAt() to access the array members (each in this case a class)
                                > is just as efficient as the direct addressing of C language.[/color]

                                Do you know we are talking about less than milli-seconds here? If
                                speed is important, you can do it in assembly, it could be faster.
                                But the difference is really not big enough to make a difference
                                (depending on the context, of course).
                                [color=blue]
                                > Now, I DID RTFM as far as the a.pop_back() that you had included in your
                                > snippet, I'm not sure I understand why, but id does solve the problem I
                                > immediately saw of an empty element at .last. I still see (under a
                                > debugger) an empty at .end - not sure if this is a problem.[/color]

                                I am not sure I am following you here.
                                [color=blue]
                                >Here's where
                                > a RTFM comment is warranted. What I'm curious about now is I don't see
                                > any way to batch allocate an array (vector) of a certain size -[/color]

                                As I said

                                std::vector<int > v(10); // 10 elements

                                or

                                v.reserve(100);

                                to prevent the reallocation if less than 100 elements are inserted.
                                [color=blue]
                                >it's
                                > certainly clear that using your method will work, but it grows the array
                                > a record at a time - that seems inefficient compared to the MFC
                                > implementation and certainly compared to raw C arrays. Am I missing
                                > something? Or id this just a tradeoff situation?[/color]

                                It would be far more interesting for you to get Josuttis's "The C++
                                Standard Library". Lots and lots of nice informations in there.


                                Jonathan


                                Comment

                                Working...