473,405 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

stdout buffer problem

4
Hi, All,

I am a new member of this forum. I am transferring an C/C++ application from Solaris to Linux. The application use cursor movement to adjust the histogram of the medical images. The application works fine on Solaris for years. But on Linux, after cursor move for a short time, the image will freeze, the histogram won't be changed. I accidentally add a printf("\n") in the callback function of the cursor movement, then problem can be fixed. But there are a lot of blank line will show on the console. I try to use fflush(stdout) to replace printf("\n"). It doesn't work. Any idea and suggestion will be really appreciated. Thank you in advance.

Angela
Jul 26 '07 #1
7 2912
JosAH
11,448 Expert 8TB
Hi, All,

I am a new member of this forum. I am transferring an C/C++ application from Solaris to Linux. The application use cursor movement to adjust the histogram of the medical images. The application works fine on Solaris for years. But on Linux, after cursor move for a short time, the image will freeze, the histogram won't be changed. I accidentally add a printf("\n") in the callback function of the cursor movement, then problem can be fixed. But there are a lot of blank line will show on the console. I try to use fflush(stdout) to replace printf("\n"). It doesn't work. Any idea and suggestion will be really appreciated. Thank you in advance.

Angela
I think that's a curses/ncurses problem. That library takes care of character
display devices and there are many implementations of it. If you have the
sources (I think you have), check the man pages and try to find a 'flush' call
which you can insert at tactical places.

Note that it is not a stdout 'flush' call, it flushes (n)curses' internal buffers.

kind regards,

Jos
Jul 26 '07 #2
fxiao
4
I think that's a curses/ncurses problem. That library takes care of character
display devices and there are many implementations of it. If you have the
sources (I think you have), check the man pages and try to find a 'flush' call
which you can insert at tactical places.

Note that it is not a stdout 'flush' call, it flushes (n)curses' internal buffers.

kind regards,

Jos

Thank you Jos. Do you mean I should add a ncurses flush call in my application code? I am not familiar with ncurses code. If yes, do you have any sample code I can reference? Our Solaris version application didn't use any curses/ncurses code. Is this a Linux problem? --Angela
Jul 26 '07 #3
JosAH
11,448 Expert 8TB
Thank you Jos. Do you mean I should add a ncurses flush call in my application code? I am not familiar with ncurses code. If yes, do you have any sample code I can reference? Our Solaris version application didn't use any curses/ncurses code. Is this a Linux problem? --Angela
Before you dig deeper into that (n)curses stuff, can you show some (relevant)
snippets of code? Maybe (n)curses has nothing to do with it; I was just guessing.

Is the output actually character based? Or are you staring at a gui of some sort?

kind regards,

Jos
Jul 26 '07 #4
fxiao
4
Before you dig deeper into that (n)curses stuff, can you show some (relevant)
snippets of code? Maybe (n)curses has nothing to do with it; I was just guessing.

Is the output actually character based? Or are you staring at a gui of some sort?

kind regards,

Jos
Thank you again, Jos. The output is not character based. We actually have the application control panel GUI which is displayed on the computer monitor (display 0), and have two medical viewboxes are installed as display 1 and display 2. The images are displayed on the two viewboxes. We use the control panel to control all image activities. One of the activities is using trackball to adjust the image histogram. We use USB trackball on Linux. It move faster than the PS/2 trackball on Solaris. Please see the following snippets of code.
Expand|Select|Wrap|Line Numbers
  1. void cursor_motion_callback(Widget w, XtPointer c, XEvent *event, Boolean *ctd)
  2. {
  3.     // add printf here to fix the image frozen problem, add fflush(stdout) here 
  4.     // doesn't work
  5.     // printf("\n") 
  6.  
  7.     if (!mouse_adjustment)
  8.       return;
  9.     ......
  10.     window = (v_x / MOUSE_SCALE) + WINDOW_MIN;
  11.     level = (v_y/MOUSE_SCALE) + LEVEL_MIN;
  12.     window_level_change();
  13.     ......
  14. }
Jul 26 '07 #5
JosAH
11,448 Expert 8TB
Thank you again, Jos. The output is not character based. We actually have the application control panel GUI which is displayed on the computer monitor (display 0), and have two medical viewboxes are installed as display 1 and display 2. The images are displayed on the two viewboxes. We use the control panel to control all image activities. One of the activities is using trackball to adjust the image histogram. We use USB trackball on Linux. It move faster than the PS/2 trackball on Solaris. Please see the following snippets of code.
Expand|Select|Wrap|Line Numbers
  1. void cursor_motion_callback(Widget w, XtPointer c, XEvent *event, Boolean *ctd)
  2. {
  3.     // add printf here to fix the image frozen problem, add fflush(stdout) here 
  4.     // doesn't work
  5.     // printf("\n") 
  6.  
  7.     if (!mouse_adjustment)
  8.       return;
  9.     ......
  10.     window = (v_x / MOUSE_SCALE) + WINDOW_MIN;
  11.     level = (v_y/MOUSE_SCALE) + LEVEL_MIN;
  12.     window_level_change();
  13.     ......
  14. }
So (n)curses has nothing to do with this; it's an X (XWindows) thing. It's still
like crystal ball staring to me as far as I can judge from here. The printf() hack
is most certainly a nono. What happens if you remove that little if-test?

OTOH was that method alterted specifically for Linux? Sorry that I can't give you
a more specific answer.

kind regards,

Jos
Jul 26 '07 #6
fxiao
4
So (n)curses has nothing to do with this; it's an X (XWindows) thing. It's still
like crystal ball staring to me as far as I can judge from here. The printf() hack
is most certainly a nono. What happens if you remove that little if-test?

OTOH was that method alterted specifically for Linux? Sorry that I can't give you
a more specific answer.

kind regards,

Jos
Thank you Jos. I can't remove that little if-test. If I do it, I'll get in a dead lock and I can't move the trackball to any where I want. The image frozen problem only happens on Linux. For Solaris, I don't need add printf("\n").

Angela
Jul 27 '07 #7
JosAH
11,448 Expert 8TB
Thank you Jos. I can't remove that little if-test. If I do it, I'll get in a dead lock and I can't move the trackball to any where I want. The image frozen problem only happens on Linux. For Solaris, I don't need add printf("\n").

Angela
You can't use that printf("\n") anyway because it would distort the image on your
screen. <thinking out loud> So you have multiple threads running; a printf()
yields control to another thread (or so I understood); if you don't use it the entire
thing locks up; not on Solaris but just on your Linux system. Is there another
way you can yield the current thread? Do you use pthreads?<thinking out loud/>

kind regards,

Jos
Jul 27 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: MK | last post by:
I have a Win32 console application (SNMPUTIL.EXE) which listens to incoming SNMP messages: C:\>snmputil trap snmputil: listening for traps... When a trap is generated on a remote server, it...
1
by: Evgeni Sergeev | last post by:
While I can make a verbatim copy of a file like this: file1 = file('ready.pdf', 'rb') file2 = file('out.pdf', 'wb') buffer = file1.read(256) while buffer: file2.write(buffer) buffer =...
1
by: Oz | last post by:
This is long. Bear with me, as I will really go through all the convoluted stuff that shows there is a problem with streams (at least when used to redirect stdout). The basic idea is that my...
4
by: Oz | last post by:
This is long. Bear with me, as I will really go through all the convoluted stuff that shows there is a problem with streams (at least when used to redirect stdout). The basic idea is that my...
3
by: Harayasu | last post by:
Hi, Using fgets() I can read from stdin and with fputs() I can write to stdout. Now I have two programs, one writing to stdin and the other one reading from stdin. And I would like the second...
4
by: Ramprasad A Padmanabhan | last post by:
I am running a program within another and reading the output. My problem is that all outputs are delayed because of bufferring Can I tell printf to print all outputs immediately and not buffer...
5
by: Philip Hölzenspies | last post by:
Hi All, I have been crunching my brains on this one all day. I use this library that creates output I want, but it can only write it to a file or the stdout. The problem is that I don't want to...
2
by: Markus Pitha | last post by:
Hello, Some time ago I tried to find a solution for preventing buffer overflows in stdin. I thought getc was the solution but today I came to a problem. I wanted to use my cognitions for a...
7
by: Pietro Cerutti | last post by:
Hi group, I just noticed that a malloc w/out relative free occurs in the standard C library (or at least, on my implementation of it). #include <stdio.h> int main(void) { printf("%s\n",...
4
by: lovecreatesbea... | last post by:
For example, in Bourne Shell both stdout and stderr can be re-directed to /dev/null, $ ./a.out 2>&1 /dev/null then is there any difference still?
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.