DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: c++ array

  1. #1
    Join Date
    Nov 2006
    Posts
    2

    Question c++ array

    Hi,
    does anyone know how I can define a 2D matrix that will change size according to users requierments. I was thinking of using a 2 dimention array but then how do I define it's size to be a variable so the size will change. I've been trying to get it for a while and I can't figure it out maybe you can help me?

  2. #2
    Join Date
    Nov 2006
    Posts
    12
    The only ways are
    a. use a linked list but not recommended if ur quite new to C++
    b. use Vectors. Vectors can automatically change size when u add new elements to them

  3. #3
    Join Date
    Nov 2006
    Posts
    2
    I realy appriciate the respons but I'm farlly new to c++ so I don't know the liked list method but do you know how I can define the vector method for more than 1D?

  4. #4
    Join Date
    Dec 2003
    Posts
    3,366
    vector<vector<int> >

  5. #5
    Join Date
    Dec 2003
    Posts
    3,366
    You might use a C array instead for performance. Vectors are a little sluggish (powerful, but very heavy compared to a pure array). I tried to use them in my latest matrix class but they were just too much for real-time processing.

    My matrix class uses a large, single dimensional pure array that is allocated at program start (its a static variable in the matrix class) and the class manages its own memory by doling out slices of that array. Its a lot like what lapack & friends do but instead of passing the working array to the routines, its just already available. I hooked in an option to allocate dynamic memory to individual instances but usually I use the pre-existing memory for the speed. The matrices are reshaped internally to appear to be 2D instead of 1D for some algorithms, for other algorithms a single loop over the 1D memory is muct faster! It depends largely on your matrix application, mine are smallish and for control theory apps, rarely exceeding a 50X50. Also sparse matrices require a different storage method & algorithms tailored for sparse matrices are completely different from their counterparts. The one drawback to my matrix class is the shared memory is not thread safe, which is not a problem for my controller (its a tight loop, with no other tasks to thread out) but could be an issue for other applications.

Similar Threads

  1. Replies: 4
    Last Post: 11-08-2006, 04:19 PM
  2. Replies: 7
    Last Post: 03-07-2006, 05:34 PM
  3. redim help !!!
    By angelito in forum VB Classic
    Replies: 1
    Last Post: 11-21-2005, 07:16 AM
  4. Dynamically allocating a 2d array
    By nnp in forum C++
    Replies: 6
    Last Post: 11-01-2005, 10:05 AM
  5. Replies: 2
    Last Post: 04-15-2005, 09:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center