我只是用gprof描述了我的程序,得到了这个:
100.01 0.01 0.01 23118 0.43 0.43 std::vector<int, std::allocator<int> >::operator=(std::vector<int, std::allocator<int> > const&)
Run Code Online (Sandbox Code Playgroud)
这让我感到困惑,因为它说使用=运算符时它使用了100.01%的时间.我是否正确地猜测这意味着它只是一直在复制数据,是否允许程序使用多少内存?
这是一个相关的帖子这一个,因为它使用相同的程序交易,但现在我实现了它的迭代,并不再递归的,但我仍然得到SIGSEGV(但后来)运行程序时.我对我的程序进行了一些其他更改以缩小范围,我认为将对象向量更改为ptr向量到堆上的对象确实给了我一些额外的回合(大约200),但仍然崩溃.我建议以某种方式保存程序中的变量的内存耗尽,但是当我转储程序的堆栈大小时:
rlimit rlim;
getrlimit(RLIMIT_STACK,&rlim);
std::cout << "rlim_cur ist:" << rlim.rlim_cur << std::endl;
std::cout << "rlim_max ist:" << rlim.rlim_max << std::endl;
Run Code Online (Sandbox Code Playgroud)
输出是:
rlim_cur ist:8388608
rlim_max ist:18446744073709551615
Run Code Online (Sandbox Code Playgroud)
这似乎是相当大,并没有用尽,是否有任何其他相关限制转储,以进一步缩小我的问题,并希望解决它?
这里调试器的转储:
Program received signal SIGSEGV, Segmentation fault.
0x000000000040b2a0 in Town::get_cur_capacity (this=0x0) at ./solver/Darstellung.cpp:98
98 return left_over_capacity;
(gdb) backtrace
#0 0x000000000040b2a0 in Town::get_cur_capacity (this=0x0) at ./solver/Darstellung.cpp:98
#1 0x000000000040b9ab in Town::compare_by_capacity (eins=0x0, zwei=0x0) at ./solver/Darstellung.cpp:135
#2 0x00000000004124c7 in std::__move_median_first<__gnu_cxx::__normal_iterator<Town**, std::vector<Town*> >, bool (*)(Town const*, Town const*)> (__a=..., __b=..., __c=...,
__comp=0x40b98e <Town::compare_by_capacity(Town const*, Town const*)>) …Run Code Online (Sandbox Code Playgroud) 我得到一个八位字节(字节)和许多相关位,我想保留该给定字节的前n个(相关位)并将剩余的位设置为零.
例如
前4位相关的数字217将转换为208
0 0
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
+-+-+-+-+-+-+-+ ==> +-+-+-+-+-+-+-+
1 1 0 1 1 0 0 1 1 1 0 1 0 0 0 0
Run Code Online (Sandbox Code Playgroud)
前8个(或更多)位相关的数字255根本不会改变
0 0
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
+-+-+-+-+-+-+-+ ==> +-+-+-+-+-+-+-+
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Run Code Online (Sandbox Code Playgroud)
我写了这个函数来解决问题
(defun …Run Code Online (Sandbox Code Playgroud) 我想创建一个新的sqlite3数据库.看一下clsql的例子,我发现了这个场景.这意味着
(ql:quickload "clsql")
(ql:quickload "clsql-sqlite3")
(uffi:def-function
("create_iso_8859_15_ci_collation" create-coll)
((db sqlite3:sqlite3-db))
:returning :int
:module "sqlite3-utils")
(clsql:connect (list "home/user/test.db" #'create-coll) :database-type :sqlite3)
Run Code Online (Sandbox Code Playgroud)
应该创建一个新的数据库.但相反,我得到:
外来函数"create_iso_8859_15_ci_collation"未定义.[SB-KERNEL类型的条件::未定 - 异常 - 错误 - 错误]
如何从头开始创建新的sqlite3数据库?
我经常想要输出列表并在列表中打印它们的位置,例如
'(a b c) 会成为 "1:A 2:B 3:C"
由于FORMAT已经支持迭代给定列表,我想知道它是否也提供某种计数指令?
例如,FORMAT字符串可能看起来像这样:"~{~@C:~a~}"反之亦然~@C.
想象一下,我得到了一些宏调用的函数来返回一个像这样的表达式
(do-something 'argument)
Run Code Online (Sandbox Code Playgroud)
因此功能必须看起来像
(defun form-expression (arg)
`(do-something ',arg))
Run Code Online (Sandbox Code Playgroud)
但是当调用时(form-expression "foobar"),由于包装宏必须接收字符串作为参数,结果是:
(do-something '"foobar")
Run Code Online (Sandbox Code Playgroud)
如何"删除"给定字符串的引号?
我有一个外部托管的空存储库。我现在想在本地创建一个由该源控制的 Intellij/maven 管理的 Java 项目。
我试过:
1>check out from source control
2>"would you like to create an IDEA proect for the sources you have checked out?" - YES
3>import from external model
4>configure stuff
5>select maven projects to import
Run Code Online (Sandbox Code Playgroud)
现在我被卡住了,因为列表是空的。
我也试过
1> setting up the maven project manually
2> initializing the git repository in root directory
3> adding origin
4> importing project into intellij
5> configuring the root directory, as suggested by intellij, for git
6> committing changes
7> selecting …Run Code Online (Sandbox Code Playgroud) 我有下表允许 NULL 值
CREATE TABLE test (
test int,
test2 int);
Run Code Online (Sandbox Code Playgroud)
常规查询允许插入 NULL 值:
INSERT INTO TABLE test (test, test2) VALUES (NULL, NULL)
Run Code Online (Sandbox Code Playgroud)
但是,使用 cl-dbi 不起作用
(cl-dbi:execute
(cl-dbi:prepare connection
"INSERT INTO test (test, test2)
VALUES (?,?)")
nil
nil)
Run Code Online (Sandbox Code Playgroud)
结果是
DB Error: invalid input syntax for type timestamp: "false" (Code: 22007)
Run Code Online (Sandbox Code Playgroud) 我实现了一个递归算法,该算法运行了大约 1730 次递归,然后因神秘的 SIGSEGV 而崩溃。我尝试了我的 gdb 并得到以下输出:
Program received signal SIGSEGV, Segmentation fault.
0x000000000040b7da in Town::get_cur_capacity (this=0x61efe0) at ./solver/Darstellung.cpp:54
54 return left_over_capacity;
(gdb) print 0x61efe0
$1 = 6418400
(gdb) print *0x61efe0
Cannot access memory at address 0x61efe0
(gdb) print this
$2 = (const Town * const) 0x61efe0
(gdb)
Run Code Online (Sandbox Code Playgroud)
调试器怎么知道它应该是一个 const Town 指针,但无法访问内存给我转储?我很确定这个方法中没有错误,因为它在崩溃前被使用了几千次,就像程序中的所有其他函数一样。有没有可能这是与操作系统相关的问题?我正在使用 Linux Ubuntu 64 位。
我的简化算法:
bool solveproblem(ptr_to_model) {
if( way_one(ptr_to_model) )
return true;
if(way_two(ptr_to_model) )
return true;
if( check_if_solved)
return true;
return false;
}
bool way_one(ptr_to_model) {
for(go_through_current_problem_configuration) …Run Code Online (Sandbox Code Playgroud) 我的问题与此有关,因为我解决了问题,我编写了自己的排序算法(简单的插入排序),并且它有效.我对此感到非常惊讶,因为我认为标准库已经过充分测试.是否有任何已知的特殊情况std::sort可能会搞乱?
我想使用标签名列表来定义用这些函数启动的线程的顺序/数量.但它不起作用,因为SBCL抱怨:
DO-STUFF不会退化.
例如:
(labels ((do-stuff (argI argII) (values argI argII))
(do-stuff-II (argI argII) (values argII argI)))
(mapcar #'(lambda(name)
(sb-thread:make-thread name :arguments '(1 2)))
'(do-stuff do-stuff-II do-stuff)))
Run Code Online (Sandbox Code Playgroud)
使用宏将列表扩展为:
(labels ((do-stuff (argI argII) (values argI argII))
(do-stuff-II (argI argII) (values argII argI)))
(let ((threads nil))
(push (sb-thread:make-thread #'do-stuff :arguments '(1 2)) threads)
(push (sb-thread:make-thread #'do-stuff-II :arguments '(1 2)) threads)
(push (sb-thread:make-thread #'do-stuff :arguments '(1 2)) threads)
threads))
Run Code Online (Sandbox Code Playgroud)
有效,但由于使用了不必要的让和推动,这让我觉得不那么优雅.
我该如何修复我的第一种方法?我必须写一个宏吗?
我想检索字符串,由write进一步处理生成而不做任何实际输出,但write似乎总是也输出到REPL
CL-USER>(let ((err-string (write (make-instance 'error) :stream nil)))
(do-awesome-stuff-with-string err-string))
<ERROR> ;;this is the printing I want to get rid of
"awesome-result"
Run Code Online (Sandbox Code Playgroud)
为什么write仍然输出到REPL中,我该如何摆脱它?