![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
&C++库研究笔记
文章平均质量分 52
GeoAnt
这个作者很懒,什么都没留下…
展开
-
C++库研究笔记——函数名的宏定义
6.47 Function Names as Strings:http://gcc.gnu.org/onlinedocs/gcc/Function-Names.htmlGCC provides three magic variables that hold the name of the current function, as a string. The first of these原创 2013-07-29 22:09:40 · 3145 阅读 · 0 评论 -
C++库研究笔记——使用assert还是exception?
design by contract tests by assert or by exception?今天也在考虑这个问题,google了下,投票最多的是:The rule of thumb is that you should use assertions when you are trying to catch your own errors, and exceptions w翻译 2013-09-29 23:16:29 · 1234 阅读 · 0 评论 -
C++库研究笔记——内存池实现
Why to use memory pool and how to implement it(推荐,通过双向链表实现,代码逻辑经过仔细推敲,未发现任何问题)按固定大小分配C++库研究笔记——用C语言函数指针包装内存分配、释放(虽然简单,但逻辑清晰,未发现问题(单链表实现),按对象分配注:google 上排名第一的memory pool 实原创 2013-08-22 22:09:42 · 1015 阅读 · 0 评论 -
C++库研究笔记——Linux下是否需要使用memory pool?
Linux Slab分配器(一)--概述Linux slab 分配器剖析做了一些测试:发现linux使用内存池与否没有明显差别,仅仅有2倍。 Linux内存处理机制已经很好,一般情况下,确实没有必要在用内存池??? 不知道大家持什么样的观点。速度测试:In [use pool]:0.00560116768 secondsIn [ no翻译 2013-09-30 02:49:27 · 1527 阅读 · 0 评论 -
C++库研究笔记—— 对function类定义的修正
在写一个数值优化库tau, 这是一个很小的改动,却事关系全局,是一个有意义的改动template class function{public: //array1d x0(2, 1.0f); //function(x0,g0), 检测不出 x0 与 eval中的dim 是否一致 T operator()(const array1d& x, array原创 2013-10-04 21:55:16 · 678 阅读 · 0 评论 -
C++库研究笔记—— [真正正确?]多维数组动态分配正确方式?(之一)
int **array2D;//假定数组第一维长度为m, 第二维长度为n//动态分配空间array2D = new int *[m];for( int i=0; i<m; i++ ){ array2D[i] = new int [n] ;}//释放for( int i=0; i<m; i++ ){ delete [] arrar2D[i];}delete array2D;表面上没有问题,实际存在潜在可能的内存泄漏:在for循环中,一旦某一个new 失败(内存不够o原创 2013-10-06 13:32:17 · 998 阅读 · 0 评论 -
C++库研究笔记——赋值操作符operator=的正确重载方式(2)
C++库研究笔记——赋值操作符operator=的正确重载方式(三个准则)总结了下,更加标准的写法是:template array1d& array1d::operator=(const array1d& other){ if(this!= &other) { if((*this).size()!=other.size()) {原创 2013-09-28 03:11:09 · 729 阅读 · 0 评论 -
C++库研究笔记——#if #elif 的错误使用
在了跟头,无论is_ar为多少,始终输出 "not"template//ant::is_arithmetic::value >class Test{public: void test() {#if is_ar cout<<"is\n";#elif !is_ar cout<<"not\n";#endif cout<<"is_arr="<<原创 2013-09-29 02:17:51 · 2139 阅读 · 0 评论 -
C++库研究笔记——程序的本地化
乱谈Qt程序之i18n的实现(从C++到Qt)5楼 jacklondon 2011-08-24 13:17发表 [回复]a. 用 ini 文件,每种语言,一个 ini 文件,以前比较流行。b. 用 xml文件,每种语言,一个 xml 文件 .现在比较流行。比如 notepad++,dreamweaver,c. 用 资源 dll, 以前微软的 VC 文档中推荐使用。偶不看好,原创 2013-10-25 19:56:41 · 642 阅读 · 0 评论 -
C++库研究笔记 error: templates may not be ‘virtual’
class function{public: template virtual T operator()(const array1d& x, array1d& g)const=0; virtual ::std::string functionName()const { return "f(x)"; } virtual ::std::string gradien原创 2013-11-13 14:33:33 · 1619 阅读 · 0 评论 -
C/C++文件之eof()误区
http://www.google.com.hk/#newwindow=1&q=c%2B%2B+eof+&safe=strictC/C++文件之eof()原创 2013-12-03 17:46:24 · 1011 阅读 · 0 评论 -
用C++ 模板做代码设计的三类方法及代码——基于策略Policy-based design
列出了3个方法,还有很多衍生版本,总结如下:通过继承,与static 有同样的使用接口继承:对代码改动最小:using ..., 适用于对代码已经写好,但用于追加功能,修改功能的时候static: 代码改动较继承大,需要在每个修改的地方都加上类名,适用于:代码设计阶段。优点是代码清晰明了(相对其它,最清晰)指针构造:功能最完善,适用于极其复杂的功能设计。扩展性强。缺点是,代码改动大,只能在代码设计阶段使用。原创 2014-03-17 13:36:19 · 2137 阅读 · 0 评论 -
[1-9]Profiling Code Using clock_gettime
Keeping track of what I doProfiling Code Usingclock_gettime:http://www.guyrutenberg.com/2007/09/22/profiling-code-using-clock_gettime/with 45 commentsAfter raising the issue of the low r转载 2013-07-27 15:33:37 · 645 阅读 · 0 评论 -
C++库研究笔记-----补充
#ifdef ....namespace {}#endif原创 2014-10-06 15:46:29 · 480 阅读 · 0 评论 -
C++库研究笔记——使用函数模板还是类模板?+ 一个类型重复问题的两种解决方法
template<typename T>class Sin{public:T operator()(T x){...};};///////////////////////////////////////////////class Sin{public:template<typename T>T operator()(T x){...};};原创 2013-09-29 17:18:58 · 1325 阅读 · 0 评论 -
C++库研究笔记——va_list、va_start、va_arg、va_end
va_list、va_start、va_arg、va_end的原理与使用http://www.cplusplus.com/reference/cstdarg/va_start/http://www.cnblogs.com/hanyonglu/archive/2011/05/07/2039916.html转载 2013-09-30 02:26:20 · 649 阅读 · 0 评论 -
C++库研究笔记——一个类型重复问题的两种解决方法(方法1的缺点补充)
template class FunObj> class minimizer > {}如果我们又重新定义了FuncObj, 上面的minimizer 定义则必须改变(改变模板参数)templateclass FunObj{},这个缺陷太重要,以至于我们不应该使用这种设计,除非:你确定FunObj非常稳定,模板参数(个数,顺序等)永远不会改变。原创 2013-09-29 17:49:23 · 835 阅读 · 0 评论 -
[个人笔记]库设计——测试设计(openMvl)
#include 28 #include 29 30 #include "mvl.hpp" 31 using namespace mvl; 32 33 #include "util/graphics.hpp" 34 35 #include "tests/layout_prod_test.hpp" 36 #include "tests/layout_tr原创 2013-07-23 00:08:47 · 623 阅读 · 0 评论 -
C++库研究笔记——操作符重载实现类型转换&这样做的意义
目标:已知这个接口:std::vector add_vec(double *d1, double *d2){.....return result;}我们自定义了这个类:class array{int size_;double *data_;....};要求实现:array v1(10), v2(10);add_vec(v1, v2);留意原创 2013-07-30 17:23:57 · 1410 阅读 · 0 评论 -
C++库研究笔记——赋值操作符operator=的正确重载方式(三个准则)
C++ Operator Overloading Guidelines设计要求: a, b, c, d, e; a = b = c = d = e = 42;This is interpreted by the compiler as: a = (b = (c = (d = (e = 42)))); MyClass a, b, c; ... (a = b)翻译 2013-07-30 11:00:23 · 7613 阅读 · 0 评论 -
C++库研究笔记[1] Profile->程序执行时间统计
统计计时问题:1.clock() 函数相当的严重不准确Resolution Problems inclock():http://www.guyrutenberg.com/2007/09/10/resolution-problems-in-clock/原创 2013-07-27 16:23:52 · 733 阅读 · 0 评论 -
C++库研究笔记——生成一组随机数
当试图用srand(time(0))rand()生成一组随机数时发现,生成的数字很多都是「一样」的经过测试:srand(seed); rand() 生成随机数,当seed一样时,生成的随机数相同。所以上述「一样」的问题应该出在time(0)所以最后采用的方式是:sleep+ 高精度计时,+srand(gettime_function) +rand()不过,把gettim原创 2013-08-03 12:52:47 · 1055 阅读 · 0 评论 -
C++库研究笔记——命名空间namespace 嵌套后的作用域问题
总结:1.::ant 表根命名空间,或匿名空间2.同时存在 ::ant::i 和::ant::blas::i, ant::detail::i时,在::ant::detail中使用i时,默认调用ant::detail::i3.平级namespace 调用用,要加相应的命名空间4.域内命名空间可省5.即使存在多个相同名字的命名空间,不会报错,按最局部分调用原则调用,如同全局变量与原创 2013-08-03 13:45:10 · 9413 阅读 · 0 评论 -
C++库研究笔记——policy-base 实现
From: stackoverflow#include struct InkPen{ void Write() { this->WriteImplementation(); } void WriteImplementation() { std::cout << "Writing using a inkpen" <<原创 2013-07-29 02:03:53 · 673 阅读 · 0 评论 -
C++库研究笔记——几个注意(size_t)
总之,用size_t 保证可移植性,保证其可以表示出最大需要表示的长度When i is signed and size is unsigned, then i is converted to unsigned before the comparison is performed. This is part of what are called the usual arithmet原创 2013-07-29 09:32:45 · 806 阅读 · 0 评论 -
C++库研究笔记——doxygen资料记录
doxygen+VIM文档实用指南for C/C-liked Programmers:http://blog.csdn.net/clarkZHUO/article/details/1471573原创 2013-07-29 01:27:52 · 463 阅读 · 0 评论 -
C++库研究笔记——Linux 下高精度计时器
High resolution timer in Linuxhttp://stackoverflow.com/questions/6749621/high-resolution-timer-in-linuxCheck out clock_gettime, which is a POSIX interface to high-resolution timers.原创 2013-07-28 13:03:58 · 3472 阅读 · 0 评论 -
C++库研究笔记——用C语言函数指针包装内存分配、释放
源自库:SuiteSparse_config源码来自:SuiteSparse_config /* Copyright (c) 2012, Timothy A. Davis. No licensing restrictions * apply to this file or to the SuiteSparse_config directory. * Author: Tim原创 2013-08-21 22:49:20 · 1507 阅读 · 0 评论 -
C++ 库研究笔记——Linux下创建文件夹
查了很多,都不怎么完成,后在stackoverflow 上了一个失推荐不多的方案,发现是最有效的。如创建 "ab/b/c" 这个文件夹,其中,ab文件夹不要求事先不存在(若不存在,先创建)#pragma once#include #include #include #include namespace light{int mkpath(std::string s原创 2013-08-22 22:17:07 · 7008 阅读 · 3 评论 -
C++ 库研究笔记——拷贝构造函数的一个错误范例
错误的拷贝构造函数 template<class ArrayType> array1d(const ArrayType& other) { log_info("arrayType"); size_= other.size(); allocate(); // copy value for(int i=0; i<size_; i++){ data_[i]=other[i];原创 2013-08-25 14:28:21 · 973 阅读 · 0 评论 -
C++库研究笔记--用__attribute__((deprecated)) 管理过时代码
用__attribute__((deprecated)) 管理过时代码,同时保留兼容的接口Linux下:#define DEPR_AFTER __attribute__((deprecated))#define DEPR_BEFOR class DEPR_BEFOR AAA{}DEPR_AFTER;int main(int argc, char** argv){原创 2014-10-06 14:30:14 · 4362 阅读 · 0 评论