www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/18/18:30:01

From: boylesgj AT lion DOT cs DOT latrobe DOT edu DOT au (Gregary J Boyles)
Newsgroups: comp.os.msdos.djgpp
Subject: Help improving function sped needed.
Date: 18 Feb 1997 13:54:52 GMT
Organization: Comp.Sci & Comp.Eng, La Trobe Uni, Australia
Lines: 80
Distribution: world
Message-ID: <5eccbc$f31@lion.cs.latrobe.edu.au>
NNTP-Posting-Host: lion.cs.latrobe.edu.au
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

I have designed a text window class which is copied directly to video RAM after
completion of output.
Below is one of the functions of that class and it outputs a string to the
window i.e. starting from character number 'FromStringPos' for 'Length'
characters.
The StringC class contains the operator function [] which allows indexing of
the string from 1 to the length of the string.
The window is stored as a 1D array of unsigned int's and the array indexes
are calculated by the inline function ConvertIndex using the current window
X and Y coordinates and the window width.
The text attribute is stored as an unsigned int with the lower byte zeroed so
all that needs to be done is to | the string character with the text attribute
and copy it to the appropriate array element.
The if statement, inside the for loop, allows for cursor CR/LF and window
scrolling etc.
It works fine except if you are writing numerous long strings to a large
window in which case it becomes unacceptably slow.
I.E. for (I=0;I<Num;I++)
     {
       Win.GoTo(1,I+1);
       Win.Write(List[I][1]);
       Win.Write(List[I],1,Width);
     }
     This loop is too slow and there is a significant delay between pressing
     the down arrow key and the window being re-drawn and displayed.

I have tried numerous ways to improve it but none of them work and I am out of
ideas.
Can any one suggest a way of improving it?
Does debugging info in the exe file slow down program execution significantly?

void WindowC::Write(StringC &String,const int FromStringPos,const int Length)
{
  int WinIndex,Index,ToStringPos;

  ToStringPos=FromStringPos+Length-1;
  if (String.Length()<ToStringPos)
    ToStringPos=String.Length();

  for (Index=FromStringPos;Index<=ToStringPos;Index++)
  {
    // Calculate the array index location of the current character cell.
    WinIndex=ConvertIndex(CursorX,CursorY,WindowWidth);

    // Add the attribute byte to the upper byte of the character cell
    // and the next string character to the lower byte.
    Window[WinIndex]=Attribute | (unsigned char)String[Index];

    // Advance the window cursor.
    CursorX++;

    // If the character was written in the last character cell of the line.
    if (CursorX>WindowWidth)
    {
      // If the character cell was not on the last line.
      if (CursorY<WindowHeight)
      {
        // Advance the cursor to start of the next line.
        CursorX=1;
        CursorY++;
      }
      // If the character cell was on the last line in a scrolling window.
      else if ((CursorY==WindowHeight) && Scroll)
      {
        // Scroll the window down a line.
        DeleteLine(1);

        // Move the cursor to the start of the new line.
        CursorX=1;
      }
      // If the character cell was on the list line in a non-scrolling window.
      else
      {
        // Wrap the cursor to start of the first line.
        CursorX=1;
        CursorY=1;
      }
    }
  }
}

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019