Results 1 to 5 of 5

Thread: Is QMap efficient in case of frequent read access ?

  1. #1
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Is QMap efficient in case of frequent read access ?

    Hi everybody !

    I wonder if the QMap class is efficient enough in case of frequent access to the members it references ... let me give more details.

    I have a class called COpenGlTexture which is designed as follow :
    Qt Code:
    1. class COpenGlTexture
    2. {
    3. public:
    4. COpenGlTexture();
    5. COpenGlTexture(const COpenGlTexture&);
    6.  
    7. ~COpenGlTexture();
    8.  
    9. COpenGlTexture& operator=(const COpenGlTexture&);
    10.  
    11. void CreateTexture(const QString& textureName);
    12. void DeleteTexture();
    13. bool IsCreated() const { return m_bIsTextureCreated; }
    14. GLuint Texture() const { return m_nTexture; }
    15.  
    16. private:
    17. void CopyFrom(const COpenGlTexture&);
    18.  
    19. private:
    20. bool m_bIsTextureCreated;
    21. GLuint m_nTexture;
    22. };
    To copy to clipboard, switch view to plain text mode 

    As my application must display some data, using a specific texture for each data types (a data type is defined in one of my enumeration) I thought to do like this :
    Qt Code:
    1. // Part of application header's file
    2. public:
    3. enum DataType {Type1=0, Type2};
    4.  
    5. private:
    6. typedef QMap<DataType, COpenGlTexture> OpenGlTextureMap;
    7. OpenGlTextureMap m_Textures;
    To copy to clipboard, switch view to plain text mode 

    What I can also tell is that I want my application to handle many kind of data types, it will just be necessary to add a type in the private enumeration and update the paintEvent function to handle the new type.

    It seems (to me) to be good way to handle my datas but I wonder (here we go again) if the use of a QMap will give me good performances as I will have to access my map object value each time (each 100ms) I need to redraw my datas and then consuming some time(perhaps useless) calling to the constructor and affectation operator of my class.

    Finally, here are my questions :
    * is it a good way to handle my datas ?
    * is there any other way to do the same thing ?
    * is QMap efficient enough to access each 100 ms each map object value ?
    * for the moment I just have to handle 2 data types but in a close futur I may have to handle 3, 4 or much more data types ... same question as previous

    Thanks in advance.

  2. #2
    Join Date
    May 2006
    Posts
    55
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Is QMap efficient in case of frequent read access ?

    Hi
    As far as I can tell from few tests, if you look after performance of search,
    size matters :
    Under approximately 50 items, an array/vector of pairs is better
    Between 50 and 400 items, an ordered map (like QMap) works better
    Over 400, a hash map shows better performance.
    But if the usage is running through each item, array/vector of pairs
    will be the optimum.
    Hth.

  3. #3
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Is QMap efficient in case of frequent read access ?

    How did you test performances ?

  4. #4
    Join Date
    May 2006
    Posts
    55
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Is QMap efficient in case of frequent read access ?

    Hi,
    I am a bit late with my answer.
    I don't have the code anymore, I guess. But this is what I remember :
    I tested by filling randomly generated longs in a container
    and in a vector for randomly selecting the ones to search for
    and repeated the search tests for some times and measured the times
    it had taken.
    Hth

  5. #5
    Join Date
    May 2006
    Posts
    55
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Is QMap efficient in case of frequent read access ?

    Ouch, I read your first post too quickly !
    It appears that the set of your key has no hole,
    as it grows from zero without a gap, and you use
    every entry of your virtual map.
    Here, obviously, anything more complicated than a "vector"
    (an array would suffice, as it is static data --the keys are known
    at compile time--) is overkill and
    brings its overhead in time and memory consumption.
    So my advice is : stick to an array.
    Hth

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.