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

  • SEARCH
  • Home
  • 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 5933797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:01:27+00:00 2026-05-22T15:01:27+00:00

Hey so i’m making a simple text game using the pdCurses library and a

  • 0

Hey so i’m making a simple text game using the pdCurses library and a few other minor things kind of like a vertical scroller in which you avoid the randomly generated walls….
Theres two walls on lef and right made out of ‘X’ characters and blank, black space in which you can move around and avoid the ‘X’s your character is an ‘8’ and your forced to continue forward or get touched by the X’s each time a new line of the randomly generated “map” is revealed( for performance tests i made a new line shown as fast as possible).

However i’m having some performance problems as the “map” (a vector of strings) gets bigger and bigger. I do not understand the problem however as i am not using all of it at any time, i’m only pulling out parts of it to display (56 lines usually).

I’ll show you what i’ve got and hopefully someone will help or suggest a better way to accomplish my game.

Here’s the condensed, important code:
Here’s the function that is taking like .25-.75 seconds (new_map is also a vector member of the “Screen” class):

    void Insert(const Map& map, int y1, int y2) {for ( int mc = y1, nm= 0; mc< map.Contents().size() && mc< y2; mc++, nm++)
                                                 new_map[nm] = map.Contents(mc);};

Here’s the Map classes contents functions:

string Contents(int Y)      {return contents[Y];};
char Contents(int Y, int X) {return contents[Y][X];};
vector <string> Save()      {return save;};

and finally the main() which i have set so the screen updates as fast as possible… which isn’t turning out to be so fast oh and L1 is one of my “maps”…
generate adds on new lines to the map as so it never ends:

 double refreshes= 0;
for (bool quit = false; quit != true;)
{   double newTime= myStopwatch.ElapsedTime()- refreshes;
    theScreen.Insert(L1, 0+refreshes, nrows+refreshes);
    refreshes++;
    if(L1.Contents().size()<= nrows+refreshes+2)
        L1.generate();}

Thanks for any help or tips!! I know it’s pretty terrible but i just started programming 2 months ago haha! =) ask if you need any more info.

  • 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-22T15:01:27+00:00Added an answer on May 22, 2026 at 3:01 pm

    The general issue seems to be that as your data set gets larger things like copying it around (which you seem to do all the time, e.g. in your snippet you are copying strings from one vector to the other) take longer.

    Things to consider:

    1. Do you need the data that is coming
      off the screen?
    2. Can you use C style array? Those would generally be faster and you’d also be able to see more clearly where the inefficiencies are.
    3. Try thinking of your scrolling as simply moving the point from where you fetch data to the screen. You shouldn’t need to make any copies or move any data around.

    As an example for point #1 you may prefer to store your screen lines in a list and do something like:

    std::list<string> screen;
    // fill up with your initial screen.
    generate(line); // generate your new line
    screen.push_back(line); // to add a line
    screen.pop_front(); // remove a line from the top
    

    It’s not perfect (there’s memory management and some copying behind the scenes) but it will outperform copying and accumulating all the screen lines.

    As an example for point #2, consider this code:

    char screen[25][80];
    for(int y = 0; y < 25; y++)
    {
      for(int x = 0; x < 79; x++)
      {
        screen[y][x] = screen[y][x+1];
      }
    }
    

    This will “scroll” screen one character to the left. It will keep running at a constant and pretty fast time – on any modern CPU you can expect to be able to do over about a million of these scrolling operations per second.

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

Sidebar

Related Questions

Hey everyone, I'm using Virtual PC and working with a virtual hard disk (*.vhd)
Hey, I'm using Levenshteins algorithm to get distance between source and target string. also
Hey right now I'm using jQuery and I have some global variables to hold
Hey guys, first time using stackoverflow. can you guys help me debug? Heres the
Hey, I have some trouble using the stream_publish method, more exactly with the attachment
Hey guys, I got the same error when I was using kiwi to install
Hey I'm trying to creare a link that passes the link's text directly to
hey, I want to be able to have a gradient fill on the text
Hey, I got a very simple problem. I want to change a float inside
Hey so what I want to do is snag the content for the first

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.