Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. 2d dynamic memory allocation

2d dynamic memory allocation

Scheduled Pinned Locked Moved Unsolved C++ Gurus
3 Posts 3 Posters 406 Views
  • 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.
  • A Offline
    A Offline
    Atomz
    wrote on last edited by
    #1

    Hello I am new to Qt C++.
    I am trying to allocate a memory for 2d array like int** array; but its crashing.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      How are you doing the allocation ?
      Did you run your application through the debugger ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Kent-DorfmanK Offline
        Kent-DorfmanK Offline
        Kent-Dorfman
        wrote on last edited by Kent-Dorfman
        #3

        do you know that size of the array in advance?
        can you create and access it using subscripts? or what is the reason for creation by pointer...since when talking about arrays the generally accepted access method is by subscript, and only by pointer as a possible optimization later.

        std::string my2dStringArray[20][10];
        20 rows of 10 columns worth of strings now exist.

        or int myInts[] = new int[row*col];
        auto v = myInts[(col * y) + x];

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved