Results 1 to 16 of 16

Thread: strange problem passing a vector

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Qt products
    Qt3
    Platforms
    Windows
    Thanks
    53

    Default Re: strange problem passing a vector

    Quote Originally Posted by Gopala Krishna View Post
    Usually it is better to declare elements on stack rather that heap but it does depend on how you use it in you application.
    [/CODE]
    What do you mean? What's the reason lead me to allocate the vecNode(in the main) in on the stack or on heap?
    Regards

  2. #2
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11
    Thanks
    37
    Thanked 53 Times in 40 Posts

    Default Re: strange problem passing a vector

    Quote Originally Posted by mickey View Post
    What do you mean? What's the reason lead me to allocate the vecNode(in the main) in on the stack or on heap?
    I mean dont create the vecNode using new. that is, dont use
    Qt Code:
    1. vector<Node> *listNode = new vector<Node>;
    To copy to clipboard, switch view to plain text mode 
    Instead use
    Qt Code:
    1. vector<Node> listNode;
    To copy to clipboard, switch view to plain text mode 

    This removes explicit new and delete operations and simplifies code in many places. Ofcourse this is not mandatory, you might find the first solution suitable in your case.

    @Wysota: Yeah, that is the reason i told it is unconventional. But it is not "unmaintainable" - atleast in a group of experienced c++ programmers.
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  3. #3
    Join Date
    Jan 2006
    Posts
    976
    Qt products
    Qt3
    Platforms
    Windows
    Thanks
    53

    Default Re: strange problem passing a vector

    Quote Originally Posted by Gopala Krishna View Post
    Ofcourse this is not mandatory, you might find the first solution suitable in your case.
    when can it be suitable? Any examples? (for me there's no difference)...
    Regards

  4. #4
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11
    Thanks
    37
    Thanked 53 Times in 40 Posts

    Default Re: strange problem passing a vector

    Quote Originally Posted by mickey View Post
    when can it be suitable? Any examples? (for me there's no difference)...
    It might be usable when you have to share one vector amongst many instances of same or different objects. Instead of holding many copies you will be holding pointers to vectors.

    But you may note that qt's collection classes are implicitly shared and are more easier to use than stl classes. stl classes are powerful only if you know how to extract maximum from them. Otherwise qt's collection classes should suffice for most cases.
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

Similar Threads

  1. Strange shortcut problem
    By blukske in forum Qt Programming
    Replies: 0
    Last Post: 13th March 2007, 10:26
  2. Strange problem with events on Unix
    By sukanyarn in forum Qt Programming
    Replies: 2
    Last Post: 7th November 2006, 02:45
  3. Strange Problem with JPEG Support on win XP
    By caligula in forum Installation and Deployment
    Replies: 3
    Last Post: 18th September 2006, 10:36

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
  •  
Qt is a trademark of The Qt Company.