![3a3d84d4a1124f8f2b3ef985de757fc9.gif](https://img8.php1.cn/3cdc5/1e804/696/da68d5eec556ddb7.gif)
注意:
内核对象句柄,是用来标识某个内核对象的一个id
同一个对象的该id对于每个进程是不同的,具体如何实现是ms不公开的算法,以下是一个近似的,可能的算法:
进程创建时,windows系统为进程构造了一个句柄表
当该进程希望获得一个内核对象句柄或者创建一个内核对象从而获得该对象句柄时
系统会将在句柄表中增加一个表项,表项的内容中存储了指向目标内核对象的指针
同时,系统返回这个表项在句柄表中的索引作为句柄
这样,进程就通过句柄查询句柄表得到对象指针,从而可以访问该对象。
同时又由于有了句柄表的保护,可以防止对内核对象的非法操作。
我想现在大家已经能对句柄概念有所了解了,我希望我的文章能对大家有所帮助。其实如果你学过SDK编程,那对句柄的概念理解会更好,更深。如果你是直接学VC6的MFC编程的,建议你看一下SDK编程,这会对你大有好处。
structtest
![2f88ce130b654eb5dc6788e02dbcfc90.png](https://img8.php1.cn/3cdc5/1e804/696/1474f0faafcc75ad.gif)
![dbf989d57862681739b642d8621fe1f0.png](https://img8.php1.cn/3cdc5/1e804/696/c8fe779cfd13bd99.gif)
{
intnumber;
doublescore;
test*next;
}
voidreverse(test*&head)
![2f88ce130b654eb5dc6788e02dbcfc90.png](https://img8.php1.cn/3cdc5/1e804/696/1474f0faafcc75ad.gif)
![dbf989d57862681739b642d8621fe1f0.png](https://img8.php1.cn/3cdc5/1e804/696/c8fe779cfd13bd99.gif)
{
test*pe=head;
test*ps=head->next;
while(ps!=NULL)
![f70a0fde2b51b7dd92a70e712e540cf6.png](https://img8.php1.cn/3cdc5/1e804/696/4cf924619a74acce.gif)
![edb48e6f68462ea23d9a824f01de40c5.png](https://img8.php1.cn/3cdc5/1e804/696/02614d8549a691b4.gif)
{
pe->next=ps->next;//save the next point
ps->next=head;//reverse
head=ps;
ps=pe->next;
}
}![cbef093dcc044b2793832001e2365e43.png](https://img8.php1.cn/3cdc5/1e804/696/1286f660a3bff27d.gif)
1.堆区( heap ):由程序员申请分配和释放,属动态内存分配方式,若程序员不释放,程序结束时可能会由 OS 回收。不过这个内存分配很容易引起问题,如果申请的内存不释放就会造成内存泄漏;如果释放的不是所要释放的内存,则轻者引起程序运行结果出错,重者系统崩溃。
2.栈区( stack ):编译器自动分配释放,存放函数的形参值、局部变量的值,也是属于动态内存分配方式,它由系统分配,所以执行效率也高,不过自由度小,声明时就得决定其具体大小。
3.全局区(静态区)( static ):全局变量和静态变量的存储是放在一块的,而且初始化的全局变量和静态变量在一块区域,未初始化的全局变量和未初始化的静态变量在相邻的另一块区域。程序结束后由系统释放,所以也不会造成内存问题。
4.文字常量区和程序代码区,两者都是由系统分配和释放,且文字常量区和前面三区合成为程序数据区,与程序代码区相对应。
inta[100];
for(i&#61;0, c&#61;0;i<100;i&#43;&#43;)
![2f88ce130b654eb5dc6788e02dbcfc90.png](https://img8.php1.cn/3cdc5/1e804/696/1474f0faafcc75ad.gif)
![dbf989d57862681739b642d8621fe1f0.png](https://img8.php1.cn/3cdc5/1e804/696/c8fe779cfd13bd99.gif)
{
if(c&#61;&#61;0)
![f70a0fde2b51b7dd92a70e712e540cf6.png](https://img8.php1.cn/3cdc5/1e804/696/4cf924619a74acce.gif)
![edb48e6f68462ea23d9a824f01de40c5.png](https://img8.php1.cn/3cdc5/1e804/696/02614d8549a691b4.gif)
{
t&#61;a[i];
c&#61;1;
continue;
}
(a[i]&#61;&#61;t)?c&#43;&#43;:c--;
}
returnt;
转载
voidpalie1(charsrc[],charbuffer[],boolused[],intlen,intlevel)
![2f88ce130b654eb5dc6788e02dbcfc90.png](https://img8.php1.cn/3cdc5/1e804/696/1474f0faafcc75ad.gif)
![dbf989d57862681739b642d8621fe1f0.png](https://img8.php1.cn/3cdc5/1e804/696/c8fe779cfd13bd99.gif)
{
if(level&#61;&#61;len)
![f70a0fde2b51b7dd92a70e712e540cf6.png](https://img8.php1.cn/3cdc5/1e804/696/4cf924619a74acce.gif)
![edb48e6f68462ea23d9a824f01de40c5.png](https://img8.php1.cn/3cdc5/1e804/696/02614d8549a691b4.gif)
{
cout<
return;
}![df37983f39daa189b8c814e01a6a9011.png](https://img8.php1.cn/3cdc5/1e804/696/e15d818d0d4a0ce5.gif)
for(inti&#61;0;i
![f70a0fde2b51b7dd92a70e712e540cf6.png](https://img8.php1.cn/3cdc5/1e804/696/4cf924619a74acce.gif)
![edb48e6f68462ea23d9a824f01de40c5.png](https://img8.php1.cn/3cdc5/1e804/696/02614d8549a691b4.gif)
{
if(used[i])
![f70a0fde2b51b7dd92a70e712e540cf6.png](https://img8.php1.cn/3cdc5/1e804/696/4cf924619a74acce.gif)
![edb48e6f68462ea23d9a824f01de40c5.png](https://img8.php1.cn/3cdc5/1e804/696/02614d8549a691b4.gif)
{
continue;
}![df37983f39daa189b8c814e01a6a9011.png](https://img8.php1.cn/3cdc5/1e804/696/e15d818d0d4a0ce5.gif)
buffer[i]&#61;src[i];
used[i]&#61;true;
palie1(src,buffer,used,len,level&#43;1);
used[i]&#61;false;
![df37983f39daa189b8c814e01a6a9011.png](https://img8.php1.cn/3cdc5/1e804/696/e15d818d0d4a0ce5.gif)
}
}
voidpailie(charstr[])
![2f88ce130b654eb5dc6788e02dbcfc90.png](https://img8.php1.cn/3cdc5/1e804/696/1474f0faafcc75ad.gif)
![dbf989d57862681739b642d8621fe1f0.png](https://img8.php1.cn/3cdc5/1e804/696/c8fe779cfd13bd99.gif)
{
intlen&#61;strlen(str);
boolused[10];
for(inti&#61;0;i<10;i&#43;&#43;)
![f70a0fde2b51b7dd92a70e712e540cf6.png](https://img8.php1.cn/3cdc5/1e804/696/4cf924619a74acce.gif)
![edb48e6f68462ea23d9a824f01de40c5.png](https://img8.php1.cn/3cdc5/1e804/696/02614d8549a691b4.gif)
{
used[i]&#61;false;
}
charout[10];
palie1(str,out,used,len,0);
}![cbef093dcc044b2793832001e2365e43.png](https://img8.php1.cn/3cdc5/1e804/696/1286f660a3bff27d.gif)
![cbef093dcc044b2793832001e2365e43.png](https://img8.php1.cn/3cdc5/1e804/696/1286f660a3bff27d.gif)
boolrevers(charstr[])
![2f88ce130b654eb5dc6788e02dbcfc90.png](https://img8.php1.cn/3cdc5/1e804/696/1474f0faafcc75ad.gif)
![dbf989d57862681739b642d8621fe1f0.png](https://img8.php1.cn/3cdc5/1e804/696/c8fe779cfd13bd99.gif)
{
char*buffer;
inttokenreadpos,wordreadpos,wordend,writepos&#61;0;
![df37983f39daa189b8c814e01a6a9011.png](https://img8.php1.cn/3cdc5/1e804/696/e15d818d0d4a0ce5.gif)
tokenreadpos&#61;strlen(str)-1;
![df37983f39daa189b8c814e01a6a9011.png](https://img8.php1.cn/3cdc5/1e804/696/e15d818d0d4a0ce5.gif)
buffer&#61;(char*)malloc(tokenreadpos&#43;2);
if(!buffer)
![f70a0fde2b51b7dd92a70e712e540cf6.png](https://img8.php1.cn/3cdc5/1e804/696/4cf924619a74acce.gif)
![edb48e6f68462ea23d9a824f01de40c5.png](https://img8.php1.cn/3cdc5/1e804/696/02614d8549a691b4.gif)
{
returnfalse;
}![df37983f39daa189b8c814e01a6a9011.png](https://img8.php1.cn/3cdc5/1e804/696/e15d818d0d4a0ce5.gif)
while(tokenreadpos>&#61;0)
![f70a0fde2b51b7dd92a70e712e540cf6.png](https://img8.php1.cn/3cdc5/1e804/696/4cf924619a74acce.gif)
![edb48e6f68462ea23d9a824f01de40c5.png](https://img8.php1.cn/3cdc5/1e804/696/02614d8549a691b4.gif)
{
if(str[tokenreadpos]&#61;&#61;&#39;&#39;)
![f70a0fde2b51b7dd92a70e712e540cf6.png](https://img8.php1.cn/3cdc5/1e804/696/4cf924619a74acce.gif)
![edb48e6f68462ea23d9a824f01de40c5.png](https://img8.php1.cn/3cdc5/1e804/696/02614d8549a691b4.gif)
{
buffer[writepos&#43;&#43;]&#61;str[tokenreadpos--];
}
else![f70a0fde2b51b7dd92a70e712e540cf6.png](https://img8.php1.cn/3cdc5/1e804/696/4cf924619a74acce.gif)
![edb48e6f68462ea23d9a824f01de40c5.png](https://img8.php1.cn/3cdc5/1e804/696/02614d8549a691b4.gif)
{
wordend&#61;tokenreadpos;
![df37983f39daa189b8c814e01a6a9011.png](https://img8.php1.cn/3cdc5/1e804/696/e15d818d0d4a0ce5.gif)
while(tokenreadpos>&#61;0&&str[tokenreadpos]!&#61;&#39;&#39;)
![f70a0fde2b51b7dd92a70e712e540cf6.png](https://img8.php1.cn/3cdc5/1e804/696/4cf924619a74acce.gif)
![edb48e6f68462ea23d9a824f01de40c5.png](https://img8.php1.cn/3cdc5/1e804/696/02614d8549a691b4.gif)
{
tokenreadpos--;
}![df37983f39daa189b8c814e01a6a9011.png](https://img8.php1.cn/3cdc5/1e804/696/e15d818d0d4a0ce5.gif)
![df37983f39daa189b8c814e01a6a9011.png](https://img8.php1.cn/3cdc5/1e804/696/e15d818d0d4a0ce5.gif)
wordreadpos&#61;tokenreadpos&#43;1;
while(wordreadpos<&#61;wordend)
![f70a0fde2b51b7dd92a70e712e540cf6.png](https://img8.php1.cn/3cdc5/1e804/696/4cf924619a74acce.gif)
![edb48e6f68462ea23d9a824f01de40c5.png](https://img8.php1.cn/3cdc5/1e804/696/02614d8549a691b4.gif)
{
buffer[writepos&#43;&#43;]&#61;str[wordreadpos&#43;&#43;];
}
}
}![df37983f39daa189b8c814e01a6a9011.png](https://img8.php1.cn/3cdc5/1e804/696/e15d818d0d4a0ce5.gif)
![df37983f39daa189b8c814e01a6a9011.png](https://img8.php1.cn/3cdc5/1e804/696/e15d818d0d4a0ce5.gif)
buffer[writepos]&#61;&#39;\0&#39;;
strcpy(str,buffer);
free(buffer);
returntrue;
}![cbef093dcc044b2793832001e2365e43.png](https://img8.php1.cn/3cdc5/1e804/696/1286f660a3bff27d.gif)
![cbef093dcc044b2793832001e2365e43.png](https://img8.php1.cn/3cdc5/1e804/696/1286f660a3bff27d.gif)
//以上的程序需要分配内存。。![cbef093dcc044b2793832001e2365e43.png](https://img8.php1.cn/3cdc5/1e804/696/1286f660a3bff27d.gif)
![cbef093dcc044b2793832001e2365e43.png](https://img8.php1.cn/3cdc5/1e804/696/1286f660a3bff27d.gif)
![cbef093dcc044b2793832001e2365e43.png](https://img8.php1.cn/3cdc5/1e804/696/1286f660a3bff27d.gif)
![2f88ce130b654eb5dc6788e02dbcfc90.png](https://img8.php1.cn/3cdc5/1e804/696/1474f0faafcc75ad.gif)
/***************************************************************************************
![cbef093dcc044b2793832001e2365e43.png](https://img8.php1.cn/3cdc5/1e804/696/1286f660a3bff27d.gif)
voidfun(charstr[],ints,inte)
![2f88ce130b654eb5dc6788e02dbcfc90.png](https://img8.php1.cn/3cdc5/1e804/696/1474f0faafcc75ad.gif)
![dbf989d57862681739b642d8621fe1f0.png](https://img8.php1.cn/3cdc5/1e804/696/c8fe779cfd13bd99.gif)
{
chartemp;
while(e>s)
![f70a0fde2b51b7dd92a70e712e540cf6.png](https://img8.php1.cn/3cdc5/1e804/696/4cf924619a74acce.gif)
![edb48e6f68462ea23d9a824f01de40c5.png](https://img8.php1.cn/3cdc5/1e804/696/02614d8549a691b4.gif)
{
temp&#61;str[s];
str[s]&#61;str[e];
str[e]&#61;temp;
s&#43;&#43;;
e--;
}
}![cbef093dcc044b2793832001e2365e43.png](https://img8.php1.cn/3cdc5/1e804/696/1286f660a3bff27d.gif)
voidrevers2(charstr[])
![2f88ce130b654eb5dc6788e02dbcfc90.png](https://img8.php1.cn/3cdc5/1e804/696/1474f0faafcc75ad.gif)
![dbf989d57862681739b642d8621fe1f0.png](https://img8.php1.cn/3cdc5/1e804/696/c8fe779cfd13bd99.gif)
{
intstart&#61;0,end&#61;0,len;
len&#61;strlen(str);
![df37983f39daa189b8c814e01a6a9011.png](https://img8.php1.cn/3cdc5/1e804/696/e15d818d0d4a0ce5.gif)
fun(str,start,len-1);
![df37983f39daa189b8c814e01a6a9011.png](https://img8.php1.cn/3cdc5/1e804/696/e15d818d0d4a0ce5.gif)
//test
cout<
![df37983f39daa189b8c814e01a6a9011.png](https://img8.php1.cn/3cdc5/1e804/696/e15d818d0d4a0ce5.gif)
while(end
![f70a0fde2b51b7dd92a70e712e540cf6.png](https://img8.php1.cn/3cdc5/1e804/696/4cf924619a74acce.gif)
![edb48e6f68462ea23d9a824f01de40c5.png](https://img8.php1.cn/3cdc5/1e804/696/02614d8549a691b4.gif)
{
if(str[end]!&#61;&#39;&#39;)
![f70a0fde2b51b7dd92a70e712e540cf6.png](https://img8.php1.cn/3cdc5/1e804/696/4cf924619a74acce.gif)
![edb48e6f68462ea23d9a824f01de40c5.png](https://img8.php1.cn/3cdc5/1e804/696/02614d8549a691b4.gif)
{
start&#61;end;
![df37983f39daa189b8c814e01a6a9011.png](https://img8.php1.cn/3cdc5/1e804/696/e15d818d0d4a0ce5.gif)
while(end
![f70a0fde2b51b7dd92a70e712e540cf6.png](https://img8.php1.cn/3cdc5/1e804/696/4cf924619a74acce.gif)
![edb48e6f68462ea23d9a824f01de40c5.png](https://img8.php1.cn/3cdc5/1e804/696/02614d8549a691b4.gif)
{
end&#43;&#43;;
}
end--;
![df37983f39daa189b8c814e01a6a9011.png](https://img8.php1.cn/3cdc5/1e804/696/e15d818d0d4a0ce5.gif)
fun(str,start,end);
}![df37983f39daa189b8c814e01a6a9011.png](https://img8.php1.cn/3cdc5/1e804/696/e15d818d0d4a0ce5.gif)
end&#43;&#43;;
}
cout<
![df37983f39daa189b8c814e01a6a9011.png](https://img8.php1.cn/3cdc5/1e804/696/e15d818d0d4a0ce5.gif)
}![cbef093dcc044b2793832001e2365e43.png](https://img8.php1.cn/3cdc5/1e804/696/1286f660a3bff27d.gif)
![cbef093dcc044b2793832001e2365e43.png](https://img8.php1.cn/3cdc5/1e804/696/1286f660a3bff27d.gif)
//以上不需要分配多余的内存
![cbef093dcc044b2793832001e2365e43.png](https://img8.php1.cn/3cdc5/1e804/696/1286f660a3bff27d.gif)