Results 1 to 10 of 10

Thread: Vector or MyArray Class - - Suggestions

Hybrid View

  1. #1

    Thread Starter
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339

    Vector or MyArray Class - - Suggestions

    When storing units and buildings, textures...etc in VECTORS for use in a game, would it be faster and more effective for a proffesional release to write your own Array Class in which I could add class's to, get the ubound of, etc, etc....

    PHP Code:
    <template c>
    class 
    UnitArray
    {
      
    UINT m_Elements;
     
      
    void Push_Back(&Value)
      {
         
    //not sure how to go about this yet.
         //temp out a variable, copy old array info to this variable
         //create a new dynamic out of old array + 1
         //then copy the temp into the dynamic array
         //add the Value into the dynamic array
      
    }

      
    void Ubound()
      {
        return 
    m_Elements;
      }

      
    void operator[](int Index)   //i thnk this is how.....just brainstorming
      
    {
           
    //acsess data within the 
      
    }


    Basic look of the idea I am trying to get across.
    Or, should I just continue to use vectors?
    "From what was there, and was meant to be, but not of that was faded away." - - Steve Damm

    "The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm

    "When you do things right, people won't be sure if you did anything at all." - - God from Futurama

  2. #2

    Thread Starter
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339
    I wish to add.

    Whether the above I described would be faster than a vector or not, I believe it may be more intelligent to use because then I am relying more on the basic c++ code. Also then I have control over my arrays holding my units.

    Now, about the <template c>
    Em I doing that right if I create an instance of this class, and I wish c to be class Human?

    Syntax please if I am wrong, or just anyway to give me the light.
    "From what was there, and was meant to be, but not of that was faded away." - - Steve Damm

    "The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm

    "When you do things right, people won't be sure if you did anything at all." - - God from Futurama

  3. #3
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403
    A vector is pretty good performance wise, so I'm not sure it's worth the trouble of reinventing the wheel for whatever performance gain you might get.

    If you want to do it, however, there are a couple issues with your code; when you push_back, you don't want to allocate a new array every time. That would be slow. What std::vector does when there is no more space left is to double the current amount of storage you have. This turns out to be the most efficient way to do this kind of thing (really! There are proofs on it!).

    Second, you need to return a value from the operator[], either of type c or of type c&, depending on whether or not you want to store objects or references to objects.

    IMO, you should use the std::vector. If you really want a stripped-down version, the boost::Array class might be something to think about.
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

  4. #4

    Thread Starter
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339
    Hmm,very smart. So every push_back it checks to see if it is not big enough to hold the new storage, and if it isn't then it just doubles its size...smart

    well then i almost have the idea down.

    Now, I don't like the idea of BOOST, i'd rather write it myself...I dunno, it feels to much like a hand-out...i dunno, it just doesn't feel right to me to use 3rd party code. which is another reason I wish to step away from as much of Dx functions that microsoft adds, vectors...even strings i'd rather write me own class for. Save over compile size, it is mine, and i can then write to suite.
    "From what was there, and was meant to be, but not of that was faded away." - - Steve Damm

    "The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm

    "When you do things right, people won't be sure if you did anything at all." - - God from Futurama

  5. #5
    Fanatic Member riis's Avatar
    Join Date
    Nov 2001
    Posts
    551
    Originally posted by Halsafar
    Now, about the <template c>
    Em I doing that right if I create an instance of this class, and I wish c to be class Human?
    That would be templlate <class c>

  6. #6
    Fanatic Member riis's Avatar
    Join Date
    Nov 2001
    Posts
    551
    Originally posted by Halsafar
    Now, I don't like the idea of BOOST, i'd rather write it myself...I dunno, it feels to much like a hand-out...i dunno, it just doesn't feel right to me to use 3rd party code. which is another reason I wish to step away from as much of Dx functions that microsoft adds, vectors...even strings i'd rather write me own class for. Save over compile size, it is mine, and i can then write to suite.
    Well, in that case why not write your own C++ compiler?
    BTW, the STL classes are a part of the C++ standard, so that should absolutely be no reason not to use it.

    Why would you bother with writing all of the code yourself? You save a lot of time writing and debugging (!) your libraries, while that isn't your concern when you're using third party software. Just check their license how they restrict the usage.

    Third party software usually is much better tested (and in more different environments) than you could possibly achieve on your own, and hence is much more stable. (I'm not insulting your capabilities, but that just is a fact. You, on your own, do not have the same resources as BigCorp does, or someone who actually wrote a library by himself, but already has tens of thousands of users.)

    The only reason (and a very good one) I can imagine you wish to write your own libraries is for the sheer fun of it. Go for it in that case, but also take the above into consideration. Besides, it's also fun to make smart use of third party software, and combine them into your product in your unique way

  7. #7
    Fanatic Member riis's Avatar
    Join Date
    Nov 2001
    Posts
    551
    As for the performance of the STL container classes, the C++ specs state clearly how the classes should behave, and that includes things like memory management, so you can be "sure" that a vector within one library has about the same performance than another library (unless one of the libs is written really bad, like the one which is shipped with VC++6 )

  8. #8

    Thread Starter
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339
    Very true on the fact that using 3rd party code is 99% guaranteed to work due to more people testing it.

    I do believe I will look into Boost, alot of people have suggested it to me in many places.

    I did not know std was a c++ standard...thank you.

    Now with that last statement, are you saying that for example Borland will have the same function, same libraries but may be written differently?

    I know all compilers compile differently, and I'm curious to see what like Turbo C++ compiler is, and I want to get Borland.
    "From what was there, and was meant to be, but not of that was faded away." - - Steve Damm

    "The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm

    "When you do things right, people won't be sure if you did anything at all." - - God from Futurama

  9. #9
    Fanatic Member riis's Avatar
    Join Date
    Nov 2001
    Posts
    551
    Yes, C++ is designed to be portable, so it should work with different compilers (and even different platforms).

    Only if you're using some specific libraries (like DirectX, MFC, etc.) then you have a chance that they aren't available for every platform (not sure about different compilers). Boost is also designed to be used at many different platforms and compilers.

    When you're using different compilers, you can (and probably you will) run into performance differences. For example, I noticed that the functions sin, cos and tan work at "half speed" with Cygwin, compared to VC++.

  10. #10
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I've seen that quite often, new programmers who say they don't want to use 3rd party code or even the SL.
    I have no problem with people implementing, say, a linked list to find out how to do it.
    But when it comes to actually using such a thing, it is nothing short of stupid not to use the existing classes. Since the people who implement these things themselves are almost always newbies (experienced programmers know better), their classes are virtually guaranteed to be worse than the existing ones, which were written by experts. They need to be written, they need to be debugged, they need to be compiled. They provide zero advantage over existing classes.
    The one sole exception are strings, because std::string is not guaranteed to have a particular implementation. I'm working on that.
    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.

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