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 5991035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:19:46+00:00 2026-05-22T23:19:46+00:00

Hi I am getting an access violation error….. What might be the problem in

  • 0

Hi I am getting an access violation error…..

What might be the problem in my code??
When I change W and H to 10 it works fine.

#define W 100
#define H 100
#define MAX 100000
int** GetImage()
{
int **img = new int*[W];
for(size_t i = 0 ; i < W ; i++ )
    img[i] = new int[H];

for(int i=0;i<W;i++)
    for(int j=0;j<H;j++)
        img[i][j]=255;
return img;
}

int main()
{
int **image = GetImage();
float **dtr = initDistances(image);

//cuda memory allocation
int  **devImage;
float **devDt;
int sizei = W*H*sizeof(int);
int sizef = W*H*sizeof(float);

cudaMalloc((void**)&devImage, sizei);
cudaMalloc((void**)&devDt, sizef);

//copy to GPU
cudaMemcpy(devImage, image, sizei, cudaMemcpyHostToDevice);  <-- access violation here
cudaMemcpy(devDt, dtr, sizef, cudaMemcpyHostToDevice);
return 0;
}
  • 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-05-22T23:19:47+00:00Added an answer on May 22, 2026 at 11:19 pm

    Your array isn’t contiguous in memory, but you’re trying to copy it as if it were.

    To allocate a contiguous array, you’d need to do a single allocation. But you’re allocating an array of pointers and then allocating an array of integers for each of those pointers, so there’s no guarantee that img[0] immediately precedes img[1] in memory. img[0] and img[1] were allocated separately. They could be in completely different places in memory.

    Your cudaMemcpy assumes that img[0]-img[W] is one big contiguous block.

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

Sidebar

Related Questions

I am getting an access violation error in an unmanaged dll I am writing,
I am getting an error: Message: SQLSTATE[42000]: Syntax error or access violation: 1064 You
I am getting Access violation error from the debugger, but I really have no
I am continuously getting an Access Violation Error with a all my kernels which
I'm getting a (to me) weird run-time access violation error. I have a class,
I'm getting an Access Violation in DBEXPSDA40.DLL (Dev Art MS SQL Server dbexpress driver)
I'm having a problem getting access to a database which lives on a remote
I am getting an 'Access to the path is denied error message when running
I am getting an 'access is denied' error when I attempt to delete a
I am getting the following error: Access denied for user 'apache'@'localhost' (using password: NO)

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.