Thread: Read chars from screen or use indexed list

  1. #1
    Registered User
    Join Date
    Mar 2011
    Location
    Stockholm, Sweden
    Posts
    20

    Read chars from screen or use indexed list

    I have come so far with my file viewer so It's time to make an an editor out of it.
    I use ncurses in linux TTY, but i create my own window routines.( which means - I do NOT use the pre-fabricatd structs)

    So far - I have one main window where I print my array of strings- but before they are displayed I shop them to proper length so they don't wrap (to avoid problems with scrolling)
    It seems that they are wrapping, but it just my routines that show them that way,.

    I have two alternative methods to choice from when decide how to put data back to my array of strings (wchar_t).

    Either I can write the data directly to the screen - and read it back whole strings from the window..
    OR I could write directly to the screen and also one char at the time to the right place in the string .

    Is the one method more preferable before the other one.?
    I have implanted methods for both, Just need to decide which route to go.

    I suppose that the second method (both to screen and the array of strings), is more portable. But which is faster.?

    Do I need to say that I am not an very experienced programmer. :-D

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    I suppose that the second method (both to screen and the array of strings), is more portable. But which is faster.?
    Without seeing any code how can we say which is faster? Although I would not be too worried about speed. Since you say you have implemented both methods, which one is faster?

    Jim

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    I would think the second method would be the better method all around. Clearer in intention and similar or even faster in speed. However, speed really shouldn't matter unless the user is pasting a large amount of text. I guarantee that adding the character to a string will be faster than the user can type.
    If you understand what you're doing, you're not learning anything.

  4. #4
    Registered User
    Join Date
    Mar 2011
    Location
    Stockholm, Sweden
    Posts
    20
    I am not to proud of my code, I will post in in whole - or post link to it, when I can rewrite the editor within itself

  5. #5
    Registered User
    Join Date
    Mar 2011
    Location
    Stockholm, Sweden
    Posts
    20
    Quote Originally Posted by jimblumberg View Post
    Without seeing any code how can we say which is faster? Although I would not be too worried about speed. Since you say you have implemented both methods, which one is faster?

    Jim
    Bootha are like fast, if I choose to use the same kind of loop for them, But if I read the string directly from screen, I don't need to shuffle one char at the time - and I can just replace them from the screen (using teh screen as a buffert), But maybe theer is more lag in that metod...I think I stick with just shuffle chars in and out to the string's.

    Have there been timings for reading a bunch of strings from screen vs copy same amount of data one char each to a string.?
    Thankyou for you answer.

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    When you say you are reading from the screen, please explain how. The screen is an output device, normally you write to the screen not read from it.

    Jim

  7. #7
    Registered User
    Join Date
    Mar 2011
    Location
    Stockholm, Sweden
    Posts
    20
    Quote Originally Posted by jimblumberg View Post
    When you say you are reading from the screen, please explain how. The screen is an output device, normally you write to the screen not read from it.

    Jim
    To read one char I use
    Code:
    cchar_t cch;
    mvin_wch(y_pos, x_pos, &cch);
    and for reading a part of a string i use
    Code:
    cchar_t *cchstr;
    mvin_wchnstr(y_pos, x_pos, &cchstr[x_beg], len);
    The last one is untested, I have just begun experimenting reading cchars from screen so far.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Read 1000000 chars into array.
    By nenpa8lo in forum C Programming
    Replies: 10
    Last Post: 05-06-2008, 06:08 AM
  2. serial port - read chars twice
    By matze in forum Linux Programming
    Replies: 1
    Last Post: 12-07-2007, 07:32 AM
  3. About poking in memory to see chars on the screen
    By Gustaff in forum C Programming
    Replies: 2
    Last Post: 10-31-2003, 07:20 AM
  4. searching in a indexed list
    By makimura in forum C++ Programming
    Replies: 0
    Last Post: 11-12-2001, 01:33 PM
  5. linked list => indexed list
    By makimura in forum C++ Programming
    Replies: 1
    Last Post: 11-12-2001, 11:31 AM