Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. vector class memory usage [modified]

vector class memory usage [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
performancegraphics
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    James_722
    wrote on last edited by
    #1

    I am just wondering if this:

    class Vector
    {
    public:
    float x,y,z;
    };
    Vector v;

    differs from this:

    class Vector
    {
    public:
    float x,y,z;
    void Cross(Vector, Vector);
    void Dot(Vector, Vector);
    void Normalize();
    //etc.....
    };
    Vector v;

    in terms of performance.

    modified on Friday, June 4, 2010 1:56 PM

    C M A 3 Replies Last reply
    0
    • J James_722

      I am just wondering if this:

      class Vector
      {
      public:
      float x,y,z;
      };
      Vector v;

      differs from this:

      class Vector
      {
      public:
      float x,y,z;
      void Cross(Vector, Vector);
      void Dot(Vector, Vector);
      void Normalize();
      //etc.....
      };
      Vector v;

      in terms of performance.

      modified on Friday, June 4, 2010 1:56 PM

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      What do you mean by "performances" ? If you mean memory size (which I guess you mean because speed is irrelevant here): there's little difference between the two. The methods of a class are in fact not contained in each instance of the class (which means that if you instantiate 10.000 classes, the methods in the class won't have a big impact on the memory consumption). Does that answer your question ?

      Cédric Moonen Software developer
      Charting control [v3.0] OpenGL game tutorial in C++

      1 Reply Last reply
      0
      • J James_722

        I am just wondering if this:

        class Vector
        {
        public:
        float x,y,z;
        };
        Vector v;

        differs from this:

        class Vector
        {
        public:
        float x,y,z;
        void Cross(Vector, Vector);
        void Dot(Vector, Vector);
        void Normalize();
        //etc.....
        };
        Vector v;

        in terms of performance.

        modified on Friday, June 4, 2010 1:56 PM

        M Offline
        M Offline
        Maximilien
        wrote on last edited by
        #3

        what's the question ? performance is dependant on a whole lot of different factors! memory usage ? computation speed ? AFAIK, adding member function to a class does not really impact on performance.

        Watched code never compiles.

        1 Reply Last reply
        0
        • J James_722

          I am just wondering if this:

          class Vector
          {
          public:
          float x,y,z;
          };
          Vector v;

          differs from this:

          class Vector
          {
          public:
          float x,y,z;
          void Cross(Vector, Vector);
          void Dot(Vector, Vector);
          void Normalize();
          //etc.....
          };
          Vector v;

          in terms of performance.

          modified on Friday, June 4, 2010 1:56 PM

          A Offline
          A Offline
          Aescleal
          wrote on last edited by
          #4

          If you mean does implementing operations on a class as member functions add any overhead to the time it takes to execute those operations compared to an equivalent global function then the answer is no. If you use virtual functions then there's a bit of additional overhead but it's pretty minimal compared to dividing two floating point numbers. Cheers, Ash

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups