代码改变世界

MSSQL重拾记录

2012-12-29 18:16 by kennyMc, 204 阅读, 0 推荐, 收藏, 编辑
摘要::distinct修饰多列1select distinct age,name from test.dbo.t1这里就以age和name列为基准,比如12,a13,b12,a13,d执行结果就是12,a13,b13,d:order by如果不适用order by,检索出的数据的顺序没有意义,数据可能进行更新或删除,则默认顺序会受到SQL Server重用回收存储空间的影响。1select id,age,name from test.dbo.t1 order by age desc,name ascorder by多列时,仅在多个行具有相同的age值时才对name进行排序。:where字符类型默认 阅读全文

WindowsAPI进行文件操作(同步模式)

2012-12-20 02:00 by kennyMc, 1737 阅读, 0 推荐, 收藏, 编辑
摘要:先用同步模式来进行文件的写入操作#include <iostream>#include<locale.h>#include <process.h>#include <windows.h>#include <string>#include <WCHAR.H>using std::cout;using std::endl;using std::string;int main(){ char *str="测试写入文件,HELLO KENNY"; cout<<"写入文件内容:"& 阅读全文

Semaphore同步

2012-12-15 19:27 by kennyMc, 399 阅读, 0 推荐, 收藏, 编辑
摘要:信号量和事件内核对象一样,不会记录当前拥有资源的线程ID,没有线程占有权一说,信号量靠资源数量来进行同步,可用资源量等于0,代表信号量未激活,大于0,信号量被激活,并且允许资源数量个线程进入。#include <iostream>#include <process.h>#include <windows.h>#include <string>using std::cout;using std::endl;using std::string;const int num=2;int count;HANDLE _Semaphore;unsigned _ 阅读全文

使用互斥量进行线程同步,与关键段和事件的区别

2012-12-15 01:56 by kennyMc, 2735 阅读, 0 推荐, 收藏, 编辑
摘要:1 #include <iostream> 2 #include <process.h> 3 #include <windows.h> 4 #include <string> 5 using std::cout; 6 using std::endl; 7 using std::string; 8 9 const int num=2;10 int count;11 unsigned __stdcall ThreadFun(void* par);12 13 int main()14 {15 count=0;16 HANDLE handles[num] 阅读全文

WaitForSingleObjec等待Event成功引起的副作用

2012-12-13 18:13 by kennyMc, 4270 阅读, 0 推荐, 收藏, 编辑
摘要:一个自动重置事件的对象,WaitForSingleObject在等待成功以后会把事件对象设置为未触发状态(马上调用ResetEvent()函数),而手动设置事件对象不会有这个副作用。#include <iostream>#include <process.h>#include <windows.h>#include <string>using std::cout;using std::endl;using std::string;const int num=10;int count;HANDLE ThreadEvent;unsigned __st 阅读全文

引用堆中的对象

2012-12-12 00:57 by kennyMc, 315 阅读, 0 推荐, 收藏, 编辑
摘要:引用无法直接指向new关键在在堆中创建的对象,必须通过指针来做中间者。#include <iostream>#include <string>using std::cout;using std::endl;using std::string;int main(){ int *p=new int(2); int &r=*p;//r是指针p指向的int变量引用,int变量分配在堆中 cout<<"*p:"<<*p<<endl; cout<<"r:"<<r<< 阅读全文

指针相减-堆和栈结果不同

2012-12-11 22:25 by kennyMc, 299 阅读, 0 推荐, 收藏, 编辑
摘要:#include <iostream>#include <string>using std::cout;using std::endl;using std::string;int main(){ int *p; int *p1; int i=10; int j=20; p=&i; p1=&j; cout<<"指针指向栈空间"<<endl; cout<<"p:"<<p<<" *p:"<<*p<<endl; cout 阅读全文

CRITICAL_SECTION的RecursionCount

2012-12-09 03:31 by kennyMc, 1517 阅读, 0 推荐, 收藏, 编辑
摘要:CRITICAL_SECTION结构的RecursionCount字段表示该关键段的拥有线程对此资源获得关键段次数,初为0。需要注意的地方:线程对同一个关键段n次EnterCriticalSection,那么需要相应的n次LeaveCriticalSection,不然RecursionCount不是0,其他线程就没法获得资源的访问权。#include <windows.h>#include <string>using std::cout;using std::endl;using std::string;CRITICAL_SECTION cs;int count;uns 阅读全文

list.erase导致迭代器失效问题

2012-12-01 01:55 by kennyMc, 2421 阅读, 0 推荐, 收藏, 编辑
摘要:#include <iostream>#include <vector>#include <string>#include <typeinfo>#include <list>#include <deque>using std::cout;using std::endl;using std::vector;using std::string;using std::list;template<typename T>void fun(list<T> &l,const T &val){ li 阅读全文

Essential c++阅读笔记-第3章 vs2010下vector的find方法排错

2012-11-29 19:20 by kennyMc, 834 阅读, 0 推荐, 收藏, 编辑
摘要:vs2010下书上的find方法(指针哨兵)无法编译通过,这里发现2个错误1:begin和end是系统已存在的方法,返回迭代器类型,这里书上自己命名的begin和end内联函数在调用的时候会被替换成系统的,所以会出现iterator无法转换为指针的错误。2:&vec[vec.size()]这样在vs2010下计算end指针报错,无法通过越界下标来得到最后一个元素后面一个指针,只能采用头元素指针加vec.size()的方法来获得end指针。#include <iostream>#include <vector>#include <string>#inc 阅读全文