Thread: faster allocating matrix

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Code:
    //Allocate the actual data
    	int* rawData = new int[rows*cols];
     
    	//Allocate pointers to the data
    	int** data = new int*[rows];
     
    	//Point the pointers into the data
    	for (int i=0; i < rows; ++i){
    	data[i] = &rawData[cols*i];
    If you do this, then I imagine freeing the matrix would be different as well:
    Code:
    delete[] rawData;
    or
    delete[] data[0];
    Rather simpler I say, if it works.

    **EDIT**
    [edit2: snip]Oops, I thought MATLAB was a library [/edit2]
    Last edited by Hunter2; 11-15-2004 at 05:58 PM.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  2. #2
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    715
    Quote Originally Posted by Hunter2
    Code:
    delete[] rawData;
    or
    delete[] data[0];
    Rather simpler I say, if it works.
    I think that both is needed:
    Code:
    delete [] data;
    delete [] rawData;
    The line delete [] data[0] look suspicious to me, I'm not sure that it will work the job.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C - access violation
    By uber in forum C Programming
    Replies: 2
    Last Post: 07-08-2009, 01:30 PM
  2. Matrix Help
    By HelpmeMark in forum C++ Programming
    Replies: 27
    Last Post: 03-06-2008, 05:57 PM
  3. What is a matrix's purpose in OpenGL
    By jimboob in forum Game Programming
    Replies: 5
    Last Post: 11-14-2004, 12:19 AM
  4. Matrix and vector operations on computers
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 05-11-2004, 06:36 AM