Google onsite question | iOS Engineer
Anonymous User
955

Debugging & Optimization Problem

Clear Drawing Buffer

Background

You are being given a 32 bit device that is built around a 480 width by 320 height monochrome display.

Requirements

  • Two static memory buffers are defined by the OS.
  • A pointer to the drawing buffer (char OSdrawingBuffer) and a pointer to the display buffer (char OSdisplayBuffer) are available to your application.
  • Any modification to the content of the screen should be done in the drawing buffer. The display buffer contains all the pixels that are being ‘physically’ shown on screen at any given time.
  • Once the drawing of a new screen is finished, the client’s code (your code is part of a framework, distributed to external developers) should call ‘swapDisplayAndDrawingBuffers()’ to swap the 2 pointers and to present the user with the latest rendered screen.
  • Each buffer is a collection of 153,600 bytes.

Tasks

  • Debug then optimize the following piece of code:
void eraseDrawingBuffer {
static char* drawingBuffer = OSdrawingBuffer;
  int x = 0;
  int y = 0;
  int pixelIndex;
  outerLoop:
    x = 0;
  innerLoop:  
      pixelIndex = y*320 + x;
      drawingBuffer[pixelIndex] = 0;
      x = x+1;
      
      if (x <= 319) goto innerLoop;    
      y = y+1;
     
      
    if (y <=479)goto outerLoop;
    
    
}
Comments (2)