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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:42:07+00:00 2026-06-17T05:42:07+00:00

I have an exercise about optimization. I need to optimize a program which rotates

  • 0

I have an exercise about optimization. I need to optimize a program which rotates and image by 45 degrees. I know accessing arrays using pointers is more efficient, so I tried the changes below- the original code:

RGB* nrgb = (RGB *)malloc(imgSizeXY*3);//3=sizeof(RGB)
//...
for (i=imgSizeY-1; i>=0; --i)
    {
        for (j=imgSizeX-1; j>=0; --j)
        {
                //...
                int y=(i*imgSizeX+j);
                nrgb[y].r = *imgInd; //*imgInd computed earlier

The changes:

    RGB* nrgb = (RGB *)malloc(imgSizeXY*3);//3=sizeof(RGB)
    RGB* rgbInd = nrgb+imgSizeXY-1;
    for (i=imgSizeY-1; i>=0; --i)
    {
        for (j=imgSizeX-1; j>=0; --j)
        {
              rgbInd->r=*imgInd;
              --rgbInd;

but when using pointers, the program produces an erroneous output. I have been staring at it for hours, and still have no idea why. Any ideas? Thank you very much!

  • 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-17T05:42:08+00:00Added an answer on June 17, 2026 at 5:42 am

    An L1 cache hit is an order of magnitude faster than an L2 cache hit, which itself is an order of magnitude faster than a main memory access. See Numbers Every Computer Scientist Should Know. For image operations, you expect that you’re going to have to do a lot of memory reads and writes, so you should expect to primarily be concerned with cache efficiency when optimising your code.

    So concentrate on finding ways to use the caches more effectively, and don’t worry too much that your compiler isn’t optimising simple pointer arithmetic optimally.

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

Sidebar

Related Questions

For an exercise about termcaps, I have to write a program that will display
I have been given an exercise to solve the zebra puzzle using a constraint
I have been busy with a exercise where I need to compare a winning
I have a code like this, which is solved by me following a exercise
I have a C program for an exercise and it has a strange issue
For about a year I have been thinking about writing a program that writes
I have found this question in the one site which was about counting sort
As an exercise (read:interview question) in index optimisation, I need a query which is
I run into this exercise about using blocks e then calling them with yield
I'm currently learning about structs, so I have the following exercise: Set a Struct

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.