- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个 ncurses 程序,它使用 setterm 设置两个屏幕。我相信我没有正确地完成它们,因为我遇到了一堆 valgrind 错误(见下文)。知道有什么问题吗??谢谢!!
#include <ncurses.h>
SCREEN * sstderr;
SCREEN * sstdout;
int main() {
sstderr = newterm(NULL, stderr, NULL);
noecho();
sstdout = newterm(NULL, stdout, stdin);
set_term(sstdout);
mvaddstr(0, 0, "algo\n");
clrtobot();
getch();
refresh();
set_term(sstdout);
endwin();
set_term(sstderr);
endwin();
return 0;
}
Valgrind 报告:
==10283== Memcheck, a memory error detector
==10283== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==10283== Using Valgrind-3.12.0 and LibVEX; rerun with -h for copyright info
==10283== Command: ./a.out
==10283== Parent PID: 669
==10283==
==10283==
==10283== HEAP SUMMARY:
==10283== in use at exit: 1,225,551 bytes in 313 blocks
==10283== total heap usage: 328 allocs, 15 frees, 1,242,329 bytes allocated
==10283==
==10283== 296 bytes in 1 blocks are possibly lost in loss record 27 of 55
==10283== at 0x4C2CA40: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==10283== by 0x4E5B88D: _nc_makenew_sp (in /usr/lib/libncursesw.so.6.0)
==10283== by 0x4E5BB2D: newwin_sp (in /usr/lib/libncursesw.so.6.0)
==10283== by 0x4E5FBC5: _nc_setupscreen_sp (in /usr/lib/libncursesw.so.6.0)
==10283== by 0x4E5B17E: newterm_sp (in /usr/lib/libncursesw.so.6.0)
==10283== by 0x400932: main (in /home/mongo/a.out)
==10283==
==10283== 296 bytes in 1 blocks are possibly lost in loss record 28 of 55
==10283== at 0x4C2CA40: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==10283== by 0x4E5B88D: _nc_makenew_sp (in /usr/lib/libncursesw.so.6.0)
==10283== by 0x4E5BB2D: newwin_sp (in /usr/lib/libncursesw.so.6.0)
==10283== by 0x4E5FBEA: _nc_setupscreen_sp (in /usr/lib/libncursesw.so.6.0)
==10283== by 0x4E5B17E: newterm_sp (in /usr/lib/libncursesw.so.6.0)
==10283== by 0x400932: main (in /home/mongo/a.out)
==10283==
==10283== 296 bytes in 1 blocks are possibly lost in loss record 29 of 55
==10283== at 0x4C2CA40: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==10283== by 0x4E5B88D: _nc_makenew_sp (in /usr/lib/libncursesw.so.6.0)
==10283== by 0x4E5BB2D: newwin_sp (in /usr/lib/libncursesw.so.6.0)
==10283== by 0x4E5FD50: _nc_setupscreen_sp (in /usr/lib/libncursesw.so.6.0)
==10283== by 0x4E5B17E: newterm_sp (in /usr/lib/libncursesw.so.6.0)
==10283== by 0x400932: main (in /home/mongo/a.out)
==10283==
==10283== 704 bytes in 1 blocks are possibly lost in loss record 37 of 55
==10283== at 0x4C2CA40: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==10283== by 0x4E5B8AF: _nc_makenew_sp (in /usr/lib/libncursesw.so.6.0)
==10283== by 0x4E5BB2D: newwin_sp (in /usr/lib/libncursesw.so.6.0)
==10283== by 0x4E5FBC5: _nc_setupscreen_sp (in /usr/lib/libncursesw.so.6.0)
==10283== by 0x4E5B17E: newterm_sp (in /usr/lib/libncursesw.so.6.0)
==10283== by 0x400932: main (in /home/mongo/a.out)
==10283==
==10283== 704 bytes in 1 blocks are possibly lost in loss record 38 of 55
==10283== at 0x4C2CA40: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==10283== by 0x4E5B8AF: _nc_makenew_sp (in /usr/lib/libncursesw.so.6.0)
==10283== by 0x4E5BB2D: newwin_sp (in /usr/lib/libncursesw.so.6.0)
==10283== by 0x4E5FBEA: _nc_setupscreen_sp (in /usr/lib/libncursesw.so.6.0)
==10283== by 0x4E5B17E: newterm_sp (in /usr/lib/libncursesw.so.6.0)
==10283== by 0x400932: main (in /home/mongo/a.out)
==10283==
==10283== 704 bytes in 1 blocks are possibly lost in loss record 39 of 55
==10283== at 0x4C2CA40: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==10283== by 0x4E5B8AF: _nc_makenew_sp (in /usr/lib/libncursesw.so.6.0)
==10283== by 0x4E5BB2D: newwin_sp (in /usr/lib/libncursesw.so.6.0)
==10283== by 0x4E5FD50: _nc_setupscreen_sp (in /usr/lib/libncursesw.so.6.0)
==10283== by 0x4E5B17E: newterm_sp (in /usr/lib/libncursesw.so.6.0)
==10283== by 0x400932: main (in /home/mongo/a.out)
==10283==
==10283== 197,120 bytes in 44 blocks are possibly lost in loss record 53 of 55
==10283== at 0x4C2CA40: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==10283== by 0x4E5BB83: newwin_sp (in /usr/lib/libncursesw.so.6.0)
==10283== by 0x4E5FBC5: _nc_setupscreen_sp (in /usr/lib/libncursesw.so.6.0)
==10283== by 0x4E5B17E: newterm_sp (in /usr/lib/libncursesw.so.6.0)
==10283== by 0x400932: main (in /home/mongo/a.out)
==10283==
==10283== 197,120 bytes in 44 blocks are possibly lost in loss record 54 of 55
==10283== at 0x4C2CA40: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==10283== by 0x4E5BB83: newwin_sp (in /usr/lib/libncursesw.so.6.0)
==10283== by 0x4E5FBEA: _nc_setupscreen_sp (in /usr/lib/libncursesw.so.6.0)
==10283== by 0x4E5B17E: newterm_sp (in /usr/lib/libncursesw.so.6.0)
==10283== by 0x400932: main (in /home/mongo/a.out)
==10283==
==10283== 197,120 bytes in 44 blocks are possibly lost in loss record 55 of 55
==10283== at 0x4C2CA40: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==10283== by 0x4E5BB83: newwin_sp (in /usr/lib/libncursesw.so.6.0)
==10283== by 0x4E5FD50: _nc_setupscreen_sp (in /usr/lib/libncursesw.so.6.0)
==10283== by 0x4E5B17E: newterm_sp (in /usr/lib/libncursesw.so.6.0)
==10283== by 0x400932: main (in /home/mongo/a.out)
==10283==
==10283== LEAK SUMMARY:
==10283== definitely lost: 0 bytes in 0 blocks
==10283== indirectly lost: 0 bytes in 0 blocks
==10283== possibly lost: 594,360 bytes in 138 blocks
==10283== still reachable: 631,191 bytes in 175 blocks
==10283== suppressed: 0 bytes in 0 blocks
==10283== Reachable blocks (those to which a pointer was found) are not shown.
==10283== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==10283==
==10283== For counts of detected and suppressed errors, rerun with: -v
==10283== ERROR SUMMARY: 9 errors from 9 contexts (suppressed: 0 from 0)
最佳答案
这是一个 FAQ :
Perhaps you used a tool such as dmalloc or valgrind to check for memory leaks. It will normally report a lot of memory still in use. That is normal.
The ncurses configure script has an option, --disable-leaks, which you can use to continue the analysis. It tells ncurses to free memory if possible. However, most of the in-use memory is "permanent".
Any implementation of curses must not free the memory associated with a screen, since (even after calling endwin()), it must be available for use in the next call to refresh(). There are also chunks of memory held for performance reasons. That makes it hard to analyze curses applications for memory leaks. To work around this, build a debugging version of the ncurses library which frees those chunks which it can, and provides the _nc_free_and_exit() function to free the remainder on exit. The ncurses utility and test programs use this feature, e.g., via the ExitProgram() macro.
跟进评论:这里的问题是,根据编译时配置,ncurses 维护每个屏幕的窗口列表或全局窗口列表(跨所有屏幕)。在后者中,它在创建新屏幕时丢弃了列表。 Fixed now :
20170325
+ fix a memory leak in the window-list when creating multiple screens
(reports by Andres Martinelli, Debian #783486).
关于无法修复 ncurses 中的内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42903568/
我正在用 C 和 C++ 编写 ncurses 程序。我还没有找到向用户隐藏光标的方法。我在互联网上查了一下,但我发现的大多数信息要么涉及 (n)curses 的 Python/Ruby 实现,要么实
我有我的 window WINDOW *win = newwin(40, 40, 3, 3); 当输入一些文本并跨越更多行时,保留窗口内边框周围整齐空白的最佳方法是什么?我似乎找不到在 NCurses
我使用 ncurses 创建了一个单窗口菜单方案并让它运行起来。当我添加第二个窗口时,我无法再触发我的 wgetch 调用(或者看起来是这样)。 函数原型(prototype)让我有些困惑: int
我一直在测试 ncurses,我尝试使用 Windows 编写一个简单的代码,通过阅读教程中的代码,在我看来,如果仅对一个窗口进行更改,调用 wrefresh() 就足够了。所以我尝试了以下代码,但它
我是一名初学者 C 程序员,我的一项任务要求我为 Logo 编程语言编写一个解释器。为此,我想知道是否有可能在使用 ncurses 库时将屏幕拆分,以便一半保留具有常规文本输入/输出的基本终端属性,另
在 ncurses 中捕获 control+key 的正确方法是什么? 当前我正在这样做定义控制,如下所示: #define ctl(x) ((x) & 0x1f) 它工作正常,但问题是我不能同时捕捉
有没有办法在mvwprintw中使用ANSI转义码? mvwprintw(window, 0, 0,"%c[%dmCOLORED_TEXT!\n", 0x1B, 32);//doesn't work
我以前问过这样的问题,但它有点误导,因为我没有包括打印顺序。自从我了解了整个概念的变化后,我认为再问一次会更合适。 #include using namespace std; in
我对 ncurses 比较陌生,只是想知道在我开始的 ncurses TUI 中显示在终端/命令行中执行的命令输出的简单方法是什么。即像这样的伪代码(我知道它不起作用,只是为了得到重点:)目标是呈现一
我正在使用 ncurses 在 C 中创建一个基于控制台的应用程序,它接受单个键输入但也读取组合键。例如,当用户同时按下 S 键和 F 键时,我希望它运行一些功能。是否有一些像 getch() 这样的
我试图通过将值 COLOR_BLUE 设置为 rgb 值(1000, 0, 0)来将文本 block 的背景设置为红色。如果我使用 Gnome 的“终端”应用程序,背景是正确的(红色),但如果我使用
main :: IO() main = runCurses $ do setEcho False w ev == EventCharacter 'q' || ev == EventChara
我需要使用 ncurses 实现一个简单的文本阅读器,有点像 unix 的 less。 我在理解如何操作时遇到问题。我目前有一个窗口,每次我按下向下键(例如)时,我都会在适当的起点刷新所有行,给人一种
为什么这段代码在这里: #include #define WIN 5 #define WI win[0] #define WC win[1] int ymax, xmax; WINDOW *win[
我正在使用 ncurses 构建我自己的终端。我的主窗口包含 5 个其他窗口。我位于下面的窗口是提示面板。我希望在那里输入文本,并且我也希望能够在那里输入文本。我已使用 wmove 定位光标,但光标仍
我正在尝试使用 ncurses 库在屏幕的特定点上色。 我写了这段代码: #include int main(void) { initscr(); start_color();
我正在使用 ncurses 为我的应用程序制作一个简单的 TUI。我掌握了创建和打印到窗口的基础知识,但我在输入方面遇到问题。 当我写完的时候,光标定位在我写的字符串的末尾 但是当我开始打字时,光标会
我有一个基本的 Linux 发行版,运行在一台连接激光的机器上。我想开发一个界面,它允许我: 配置激光设置(例如工具栏和按钮) 显示激光的当前路径(例如图形窗口) 因为这些是最基本的机器,所以我没有安
平台:Linux 3.2.0 x86 (Debian Wheezy) 编译器:GCC 4.7.2 (Debian 4.7.2-5) 我正在编写一个需要 ncurses 提供的高级终端控制的程序,但我无
我一直在尝试自学 ncurses,到目前为止我很喜欢它。但是,我正在尝试编写一个像 pico 或 nano 这样的小型文本编辑器。到目前为止,我已经设置得相当好。我创建了一个函数来映射键。无论我做什么
我是一名优秀的程序员,十分优秀!