Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8598437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:09:01+00:00 2026-06-12T01:09:01+00:00

In C++, I am trying to copy data from one matrix to another. My

  • 0

In C++, I am trying to copy data from one matrix to another. My code is as follows:

int data[height][width];
void MyCode::setData ( int newData[height][width] )
{   
    for ( int i = 0; i < height; i ++ )
    {
        for ( int j = 0; j < width; j ++ )
        {
            data[i][j] = newData[i][j];
        }   
    }       
}

My problem here is, these “for” loops are too time consuming, and the code stops just here (maybe the memory is overloaded, I am reading video frames). I wondered about using pointers, like this:

int* data[height][width];
void MyCode::setData ( int* newData[height][width] )
{   
     data = newData;
}

But it didn’t work, I don’t know the reason. Could someone suggest me a better solution for this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T01:09:03+00:00Added an answer on June 12, 2026 at 1:09 am

    One way round this is to use a 1D array that is width * height in size. This way you can easily memcpy the data between the two.

    Its easy to work out from a row and column what the eventual position in the 1D array is by doing the following:

    int index = column + (row * width);
    

    Edit: If you must use a 2D array then one of the dimensions MUST be known.

    As such you can do the following:

    int data[height][width];
    void MyCode::setData ( int (*newData)[width] )
    {   
        for ( int i = 0; i < height; i ++ )
        {
            for ( int j = 0; j < width; j ++ )
            {
                data[i][j] = newData[i][j];
            }   
        }       
    }
    

    In C++ you really are better off using something like a template based solution or such like though as if you pass in an array with the wrong height dimension you will get problems and the compiler will not catch it.

    There are plenty of template matrix libraries around. For example:

    http://sourceforge.net/projects/tmv-cpp/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I am trying to copy alot of data from one woorkbook to another.
Im trying to copy over data from one table to another in the same
I'm trying to copy data from one Oracle schema ( CORE_DATA ) into another
I am trying to copy code from one project to another. There is one
I'm currently trying to copy data from table into another by using a SELECT
I need to copy some data from one table to another but I need
I'm trying to take data from one column, MyTable.SSN , and copy it to
Using MongoDB I'm trying to copy a database from one server to another. My
I am trying to copy a database from one server to another in id
We are trying to copy a BO Query Service from one Universe to another.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.