Operating System - HP-UX
1834187 Members
2715 Online
110064 Solutions
New Discussion

Curses and C standard functions

 
CD Ajaykumar
Occasional Contributor

Curses and C standard functions

Hi,

We have a series of curses functions used in our application. We have noticed that, in between these curses functions, some of the standard C functions like 'fprint' are also used.

Can this affect the performance of the application? If so, what are the possible consequences?

Thanks in advance
Ajay
4 REPLIES 4
Olav Baadsvik
Esteemed Contributor

Re: Curses and C standard functions


Hello,

If the use fo fprint does not cause your screen to be messed up I would not worry.
I do not think the curses routines were
written for performance, but rather to hide from the programmer
the various screen-spesific command-sequences that must be used to postition cursor, write in reverse vidoe etc.

Regards
Olav
Shannon Petry
Honored Contributor

Re: Curses and C standard functions

I concur with Olav. C print statements are extremely fast, much faster than curses routines. Unless it messes up the display(usually caused by curses functions that are not closed) it will actually give better performance than the curses routines.

Also, some of these print statements may be required to get user input to the application.

Regards,
Shannon
Microsoft. When do you want a virus today?
A. Clay Stephenson
Acclaimed Contributor

Re: Curses and C standard functions

It is normally a bad idea to mix printf()'s,putchar()'s, etc. with curses output - at least to the same device. The problem is that curses keeps an idea of what the current screen is and what its window (buffer) is. If the process also write with a printf then curses has no idea that this has happened and the screen contents are very likely to be garbaged. If you must do this then the correct sequence is to do a touchwin() before any additional curses output. Touchwin() causes curses to "forget" everything about a window so that the next refresh will re-display the entire screen.


Note that output to other devices and files that are not under curses is perfectly okay.
If it ain't broke, I can fix that.
Wodisch
Honored Contributor

Re: Curses and C standard functions

Hi Ajay,

"curses" minimizes the amount of characters/bytes sent to the terminal, it does not minimize the amount of CPU time.
But as it was designed and coded back in the days when a user was supposed to use only dozens or hundreds of KB (kilo!) of virtual address space, and to run on the slow CPUs of those times, it won't be any burden for today's systems.
"fprintf" can confuse "curses", but only if it is sent the same terminal (window). And in that case I would prefer the "curses" routines, anyway - since you ARE already using those!
I do not see any point in using "curses" to some degree, and do something else to some other degree, and then have the need to "touchwin()" every now and then to keep both in sync.
If you need to learn programming "curses", there is a very small/thin O'Reilly book about it, or you might find Marc Rochkind's programming book in your company's library, already.

FWIW,
Wodisch