- 博客(54)
- 收藏
- 关注
原创 简单sharedptr
#include<iostream>using namespace std;template<class T>class SharedPtr { private: T* ptr_; int* pCount_; public: SharedPtr(T* p) : ptr_(p), pCount_(new int(1)) {} SharedPtr(SharedPtr& s) { ptr_ = s.ptr_; .
2020-06-04 15:41:32
190
原创 shared_ptr
shared_ptr模板类有一个__shared_count类型的成员_M_refcount来处理引用计数的问题。__shared_count也是一个模板类,它的内部有一个指向Sp_counted_base_impl类型的指针_M_pi。所有引用同一个对象的shared_ptr都共用一个_M_pi指针。当一个shared_ptr拷贝复制时, _M_pi指针调用_M_add_ref_copy()
2017-01-23 19:40:39
555
原创 任意进制转换
void revert(char* psrc) { size_t len = strlen(psrc); if (len < 2) return; char tmp = 0; size_t i = 0, j = 0; for (i = 0, j = len - 1; i < j; ++i, --j) { tmp = psrc[i];
2016-08-11 20:01:02
681
转载 stl set
TType of the elements. Each element in a set container is also uniquely identified by this value (each value is itself also the element's key).Aliased as member types set::key_type and set::value_ty
2015-03-18 15:22:32
408
转载 sizeof 实现
#define sizeof_v(var) ((size_t) ((char *)(&(var) + 1) - (char *)&(var)))#define sizeof_t(type) ((size_t) ((type *)0 + 1)
2015-01-15 15:28:47
482
转载 sizeof
struct的sizeof1. 各成员变量存放的起始地址相对于结构的起始地址的偏移量必须为该变量的类型所占用的字节数的倍数。2. 同时VC为了确保结构的大小为结构的字节边界数(即该结构中占用最大空间的类型所占用的字节数)的倍数,所以在为最后一个成员变量申请空间后,还会根据需要自动填充空缺的字节。struct MyStruct{char dda;
2014-02-27 12:08:52
447
原创 shell 赋值
No space permitted on either side of = sign when initializing variables.# What happens if there is a space?# "VARIABLE =value"#% Script tries to run "VARIABLE" command with one argument, "=value
2014-02-25 09:33:33
523
原创 sort对第三个参数的使用
template void __unguarded_linear_insert(_RandomAccessIter __last, _Tp __val, _Compare __comp) { _RandomAccessIter __next = __last; --__next; while (__comp(__val, *__next)
2014-01-10 19:23:47
1948
原创 求素数
对于一个数n,假如可以写成 n = p * q设 m = sqrt ( n );若 p > m q > m 则 p * q > m * m = n所以 p q 中有一个小于 sqrt ( n )
2014-01-05 15:50:37
422
原创 Shell
# !告诉系统同一行上紧跟在他后面的那个参数是用来执行本文件的程序chmod +x first./first 把脚本的完整路径告诉shell 在shell的环境变量中没有当前目录chmod u=rwx,go=rx /usr/bin/first
2013-11-06 10:52:29
649
原创 Linux命令
chgrp users a.txtchown user1 a.txtchmod -r 770 a.txtchmod u=rwx,go=rx .bashrccd 是 Change Directory pwd 是 Print Working Directory 癿缩写
2013-11-05 11:27:06
527
转载 Ubuntu默认启动到字符界面
原来要想默认不进入xwindows,只需编辑文件”/etc/default/grub”,把 GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash”改成GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash text”(即在GRUB_CMDLINE_LINUX_DEFAULT项的后面加上” text”),然后再运行”sudo up
2013-11-02 15:06:50
691
原创 友元函数 友元类
#includeclass C;class B;class A{ friend class C; friend bool check(A a,B b); friend bool operator>(A& a,B& b); int aNum; bool flag;public: A(bool a,int n){ flag = a; aNum = n; }};
2013-04-03 16:14:46
461
原创 以太网数据帧结构
协议类型0x0800 网际协议(IP)0x0806 地址解析协议(ARP : Address Resolution Protocol)0x 814C 简单网络管理协议(SNMP:Simple Network Management Protocol)0x86DD 网际协议v6 (IPv6,Internet Protocol version 6)0x8035 动
2013-03-28 23:37:24
1631
原创 deque 内存块管理
int arr0[2]={1,2}; int arr1[2]={3,4}; int arr2[2]={5,6}; int* arrctl[4]; arrctl[0] = arr0; arrctl[1] = arr1; arrctl[2] = arr2; int **arrmap = arrctl;
2012-12-13 18:02:16
432
原创 list sort
while (!empty()) { //把*this的第一个元素移到carry中,由于carry原来是空的,所以现在carry有了一个元素, //而*this则少了一个元素,每次循环*this都会少一个元素,直到空了为止 carry.splice(carry.begin(), *this, begin()); //对counter数组中最前面的非空项进行处理 //
2012-12-11 17:55:12
251
原创 stl template
#include #include #include using namespace std;void test_macro(){#if defined(__sgi) cout<<"__sgi"<<endl;#endif // case 2#ifdef __STL_NO_DRAND48 cout << "__STL_NO_DRAND48 defined" << e
2012-12-10 22:13:02
514
原创 type_traits
#include namespace namespace269 { /** 2两个空白类,没有任何成员,不会带来额外负担,却能通过类型代表真假,可以用于函数特化参数 */ struct __true_type { }; struct __false_type { }; template struct __type_traits {
2012-12-10 22:05:57
2260
原创 iterator_traits
#includeusing namespace std;///////////////////////////////////////////////////////////////////////////////// interator type tagsstruct my_input_iterator_tag{};struct my_output_iterator_tag{};
2012-12-10 21:55:41
435
原创 动态游标
create or replace procedure RL_SZJC_ADDNEWistmp_flag number;tmp_now date;strSql varchar2(1000);--next_id number;tmp_rec RL_SZJC%ROWTYPE;type dy_cursor is ref cursor;cur_a dy_cursor;b
2011-11-26 10:36:37
414
原创 qsort make_heap
#include#include#includeusing namespace std;int main(){ int array[]={21,5,68,73,4,98,6,3}; make_heap(array,array+8); for(int i=0;i<8;i++) cout<<array[i]<<" "; cout<<"ddddd"<<endl; return
2011-11-25 20:04:43
341
原创 CreateThread CreateMutex
#include#includeusing namespace std;HANDLE hMutex;DWORD WINAPI threadFun(LPVOID lpParamter){ char * p = (char *)lpParamter; while(1){ WaitForSingleObject(hMutex,INFINITE)
2011-11-25 19:36:33
543
原创 oracle sql join
SQL> select * from emp;EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO----- ---------- --------- ----- ----------- --------- --------- ------ 7369 SMITH CLERK 790
2011-11-08 14:04:27
1991
原创 读取文件夹下最近三天的文件名 文件按时间产生
#include #include #includevoid setYearMonth(char *nowDay,char *yesDay,char *befDay){ char date[15];//yyyymmdd*.dbf time_t now;//实例化time_t结构 struct tm *timenow;//实例化tm结构指针 time(&now); timenow
2011-11-05 15:36:23
497
转载 windows api 读取目录下所有文件
#include #include void enum_path(char *cpath){ WIN32_FIND_DATA wfd; HANDLE hfd; char cdir[MAX_PATH]; char subdir[MAX_PATH]; int r; GetCurrentDirectory(MAX_PATH,cdir); SetCurrentDirect
2011-11-05 14:39:26
3784
原创 排序实现
#include#includeconst int SIZE=9;void swap(int &a,int &b){ int temp; temp = a; a = b; b = temp; }//插入排序 稳定 void insertion_sort(int s[],int n){ int i,j; int
2011-10-31 10:57:35
350
原创 oracle note3 常用的表视图
declarev_name varchar2(10);v_sql varchar2(100);beginv_name:='name';v_sql:='select '||v_name||' from table1 where id = 1 ';execute immediate v_sql into v_name;dbms_output.put_line(v_name)
2011-10-30 13:28:31
340
原创 oracle note2 存储过程
declarex varchar2(10):='ssss';begin--x:='This is..';dbms_output.put_line('x''s value is' ||x);end;/===============================SQL> set serveroutput on-----------------if---------
2011-10-30 13:27:33
396
原创 oracle note1
list 查看缓冲区的命令 l/ 执行缓冲区的命令change 改变缓冲区的命令 c ? setsave 保存缓冲区命令@ 执行文件命令get 查看文件命令get c:\oracle\a.txtedit 编辑缓存区文件column id heading "编号"describe col dname format A10 heading "部门名称"
2011-10-30 13:26:28
325
原创 利用unsigned int 溢出
请仅使用变量声明,赋值,++,及从0开始的for循环实现一个函数f(x),在x为不小于1的整数类型的情况下,使其返回值等于x-1.#includeint f(int x){ unsigned int i,j; for(i=0; x; i++) { x++; } i++; for(j=0; i; j++) { i++; } return j;}
2011-10-29 20:02:52
3835
转载 vector 内存分配
#include #include using namespace std;int main() { vector iVec; cout << "容器 大小为: " << iVec.size() << "容器 容量为: " << iVec.capacity() << endl; //1个元素, 容器容量为1 iVec.push_back(1); cout << "容器 大小为:
2011-10-20 20:27:27
2148
转载 ORACLE外连接小结~ http://blog.youkuaiyun.com/wh62592855/article/details/4852908
//table1和table2为两个测试表 随便插入几条数据 SQL> select * from table1; ID NAME ---------- -------------------- 1 wh 2 wp 3 wq SQL> select * from table2;
2011-10-20 20:20:39
410
原创 全排列
#include int n = 0; void swap(int *a, int *b) { int m; m = *a; *a = *b; *b = m; } void
2011-10-19 15:47:08
261
原创 爬楼梯 struct union内存分配 大小端判断
#include#includeint step(int n){ if(1==n) return 1; else if(2==n) return 2; else if(3==n) return 4; else return step(n-1)+ste
2011-10-18 20:54:49
892
原创 atoi
#include#includeint myatoi(const char *str){ int result = 0; int signal = 1; if((*str>='0'&&*str<='9')||*str=='-'||*str=='+'){ if(*s
2011-10-16 18:59:04
287
原创 c ctype.h
#include#include#include#include#include#include#includestatic void prclass(const char* name,int (*fn)(int)){ int c; fputs(name,s
2011-10-13 09:19:19
458
原创 1的个数
#include#include #include "windows.h"#include "math.h"int countA(int v){ int num=0; while (v) { v &= (v-1); num++; } return num
2011-10-13 08:30:18
258
原创 最长上升子序列
#include using namespace std;int find(int *a,int len,int n)//若返回值为x,则a[x]>=n>a[x-1]{ int left=0,right=len,mid=(left+right)/2; whi
2011-10-12 19:54:50
324
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人