Results 1 to 10 of 10

Thread: two dimensional array, size determined dynamically

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #7
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: two dimensional array, size determined dynamically

    Another simple solution is to just use a 1D array:

    Qt Code:
    1. int* array = new int[rows * columns];
    To copy to clipboard, switch view to plain text mode 

    and do the 2D indexing yourself, which is very simple.

    This approach guarantees that your allocated storage occupies a single, contiguous chunk of memory, something that may be good, bad or indifferent depending on exactly what you're doing. It is probably slightly faster than performing the multiple, small allocations required by the 2D case.
    Last edited by SixDegrees; 8th June 2010 at 21:45.

Similar Threads

  1. Multi-dimensional objects array
    By matulik in forum Newbie
    Replies: 3
    Last Post: 23rd October 2011, 02:20
  2. use QVector as 2 dimensional Array
    By umulingu in forum Qt Programming
    Replies: 3
    Last Post: 1st January 2010, 12:31
  3. How to increase size of QGraphicsView Dynamically
    By Kingofhearts_sri in forum Qt Programming
    Replies: 1
    Last Post: 23rd January 2009, 08:54
  4. Replies: 0
    Last Post: 25th June 2008, 18:36
  5. Dynamically changing QGroupBox size
    By T4ng10r in forum Qt Programming
    Replies: 5
    Last Post: 30th March 2007, 15:02

Tags for this Thread

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.