Code Planet

为了发现更大的世界


  • 首页

  • 关于

  • 标签

  • 分类

  • 归档

C++内存池设计与实现(一)

发表于 2015-06-30 | 分类于 C++

C++内存池实现

什么是内存池

(Memory Pool)是一种内存分配方式。通常我们习惯直接使用new、malloc等API申请分配内存,这样做的缺点在于:由于所申请内存块的大小不定,当频繁使用时会造成大量的内存碎片并进而降低性能。使用该技术的优点是重用现有的内存块,以便减少系统调用的时间。

为什么使用内存池

主要有两点:

  • 缩短的程序分配内存的时间
  • 避免内存碎片
阅读全文 »

计算机视觉进展20年

发表于 2015-06-24 | 分类于 CV

计算机视觉的两大主要板块是:几何和识别,这里我们主要来讲述计算机视觉在1995~2015年间的进展。

1. 影像特征点检测算子(detector)和描述算子(descriptor) SIFT的诞生 (1999, 2004)

Scale invariant feature transform (SIFT) 是在1999年由 UBC 的教授 David Lowe 首次提出,并在2004年进一步完善并发表的 影像特征点检测 (detector) 和描述算子 (descriptor)。SIFT的诞生是计算机视觉里程碑式的进步,它使得 homography estimation, structure from motion, epipolar geometry 以及 机器人 (robotics) 中的SLAM 有了飞跃式的改进,正是因为SIFT好于在它之前的任何描述子, 使得匹配更加准确。SIFT不只是在geometry上有应用, 它后来广泛应用于目标识别 (Object Recognition)(见后文)。

阅读全文 »

我们的征途是星辰大海

发表于 2015-06-19 | 分类于 Photography

我们的征途是星辰大海

Sublime Text安装Ctags插件

发表于 2015-06-19 | 分类于 Tool

什么是Ctags

ctags是vim下方便代码阅读的工具,以便支持代码跳转。在sublime text中也支持该插件。

Ctags常用命令

1.$ ctags –R * ($为Linux系统Shell提示符,这个命令上面已经有所介绍)
2.$ vi –t tag (请把tag替换为您欲查找的变量或函数名)
3.:ts(ts助记字:tagslist, “:”开头的命令为VI中命令行模式命令)
4.:tp(tp助记字:tagspreview)—-此命令不常用,可以不用记
5.:tn(tn助记字:tagsnext) —-此命令不常用,可以不用记
6.Ctrl+ ]跳到光标所在函数或者结构体的定义处
7.Ctrl+ T返回查找或跳转

安装配置Ctags

1.Ctrl + ` 打开sublime text命令行。输入下面代码,自动完成Package Control安装。

1
import urllib2,os;pf='Package Control.sublime-package';ipp=sublime.installed_packages_path();os.makedirs(ipp) if not os.path.exists(ipp) else None;open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read())

2.Ctrl + Shitf + P 打开Package Control,输入ctag,确认自动完成安装。

3.在你的源代码目录下输入命令1之后,目录底下会生成.tags文件。然后就可以通过命令自动实现函数跳转了。

Have fun!

你好世界

发表于 2015-06-19

世界那么大,我想去看看!

dicom图像信息

发表于 2015-05-21 | 更新于 2015-08-15 | 分类于 vtk
`
**double*** sp = source->GetOutput()->GetSpacing(); **int*** dims = source->GetOutput()->GetDimensions(); **int*** exts = source->GetOutput()->GetWholeExtent(); **double*** bounds = source->GetOutput()->GetBounds();
cout << sp[0] << "\t" <<  sp[1] <<"\t" << sp[2] << endl; 
cout << dims[0] << "\t" << dims[1] << "\t" <<dims[2] << endl; 
cout << exts[0] << "\t" << exts[1] << "\t" <<exts[2] << endl;  cout << exts[3] << "\t" << exts[4] << "\t" <<exts[5] << endl; 
cout << bounds[0] << "\t" << bounds[1] << "\t" <<bounds[2] << endl;  cout << bounds[3] << "\t" << bounds[4] << "\t" <<bounds[5] << endl; 
`
输出结果为:
`
0.488281        0.488281        3            //spacing信息 像素距离(mm单位) 512     512     1                            //图像分辨率大小512x512
0       511     0                             //图像x,y,z的index   
511     0       0                             //x:0~511
0       249.512 0                             //spacing * index
249.512 0       0                             //可以理解为物理尺寸249.512mm
`
[来自为知笔记(Wiz)](http://www.wiz.cn/i/c09d0bb5 "来自为知笔记(Wiz)")

linux进程

发表于 2015-05-19 | 更新于 2015-08-15 | 分类于 linux
#**include** <stdio.h>
#**include** <stdlib.h> #**include** <unistd.h> **int** main(**void**) { printf("%d %d %d\n",getpid(), /*进程ID*/
getpgrp(), /*进程组ID*/
getppid()); /*父进程ID*/
printf("%d %d %d %d\n",getuid(), /*进程实际用户ID*/
geteuid(), /*进程有效用户ID*/
getgid(), /*进程实际组ID*/
getegid()); /*进程有效组ID*/
}
输出为:
{ ~ } » a.exe 5088 5088 6020 197108 197108 197121 197121 { ~ } » **ps** PID PPID PGID WINPID TTY UID STIME COMMAND 5740 6020 5740 704 pty0 197108 14:42:50 /usr/bin/**ps** 6020 4984 6020 6124 pty0 197108 14:26:10 /usr/bin/bash 4984 1 4984 4984 ? 197108 14:26:09 /usr/bin/mintty { ~ } » id uid=197108(Administrator) gid=197121(None) groups=197121(None),114(本地帐户和管理员组成员),197609(HelpLibraryUpdaters),544(Administrators),545(Users),4(INTERACTIVE),66049(控制台登录),11(Authenticated Users),15(This Organization),113(本地帐户),4095(CurrentSession),66048(LOCAL),262154(NTLM Authentication),405504(High Mandatory Level)
进程号为:5672 父进程为:6020 (bash)
用户uid: 197108 用户gid: 197121
阅读全文 »

C/C++返回内部静态成员的陷阱

发表于 2015-04-29 | 更新于 2015-08-15 | 分类于 vtk
char*inet_ntoa(structin_addrin);
将一个IP转换成一个互联网标准点分格式的字符串。
如果正确,返回一个字符指针,指向一块存储着点分格式IP地址的静态缓冲区(同一线程内共享此内存);错误,返回NULL。
这里返回的值是static型,所以对于1语句是覆盖了src的地址
`
#**include** <iostream> #**include** <Winsock2.h> **using** **namespace** std; **int** main() {     **struct** in_addr src, des;     src.s_addr = 3776385196;    //对应于172.16.23.225     des.s_addr = 1678184620;    //对应于172.16.7.100     cout << "src\t" << inet_ntoa(src) <<endl         << "des\t" << inet_ntoa(des) << endl;          cout << endl;     cout << "src\t" << inet_ntoa(src) <<endl;     cout << "des\t" << inet_ntoa(des) << endl;     system("pause");     **return** 0; }
`
运行结果
`
src     172.16.23.225 des     172.16.23.225 src     172.16.23.225 des     172.16.7.100 请按任意键继续. . .
`
[来自为知笔记(Wiz)](http://www.wiz.cn/i/c09d0bb5 "来自为知笔记(Wiz)")

从一个例子来三种内存分配方式

发表于 2015-04-10 | 更新于 2015-08-15 | 分类于 未分类

内存分配方式有3种:

1.静态存储区分配。static变量,全局变量。
2.栈分配。局部变量,形参等。
3.堆分配。动态分配,自己申请。
先来看一个例子:


1.  `char* get_string()`
2.  `{`
3.  `    char* p = new char[10];`        //堆内存
4.  `    strcpy(p,"hello");`
5.  `    return p;`
6.  `}`
7.  `
          
          
            
阅读全文 »

vtk交互器方式与回调函数

发表于 2015-04-01 | 更新于 2015-08-15 | 分类于 未分类
处理vtk鼠标事件从实现方式上看有两种方式:
1.通过继承vtk的interactorstyle父类,实现virtual类来达到目的
代码示例:

1.  `//实现interactorstyle类`
2.  `class MyVtkInteractorStyle : public vtkInteractorStyleTrackballCamera`
3.  `{`
4.  `public:`
5.  `    static MyVtkInteractorStyle *New();`
6.  `    vtkTypeMacro(MyVtkInteractorStyle, vtkInteractorStyleTrackballCamera);`
7.  `             ...`
8.  `    virtual void OnMouseMove();`
9.  `    virtual void OnLeftButtonDown();`
10.  `    virtual void OnLeftButtonUp();`
11.  `             ...`
12.  `};`
阅读全文 »
1…456…12
Lu Xiaohua

Lu Xiaohua

116 日志
33 分类
86 标签
GitHub E-Mail
© 2019 Lu Xiaohua
由 Hexo 强力驱动 v3.8.0
|
主题 – NexT.Muse v7.0.0