不知道错在哪 应该是释放看空间出错 用的编译器是vs2012 折磨死我了单步可以走一调试就出错
应该是 释放内存的错误 就是一直检查不出来;错误截图
这个是报错的地点有时显示
void __cdecl _free_base (void * pBlock)
{
int retval = 0;
if (pBlock == NULL)
return;
RTCCALLBACK(_RTC_Free_hook, (pBlock, 0));
retval = HeapFree(_crtheap, 0, pBlock);
if (retval == 0)
{
errno = _get_errno_from_oserr(GetLastError());
}
}
有时显示
/***
*int _CrtDoForAllClientObjects() - call a client-supplied function for all
* client objects in the heap
*
*Purpose:
* call a client-supplied function for all client objects in the heap
*
*Entry:
* void (*pfn)(void *, void *) - pointer to client function to call
* void * pContext - pointer to user supplied context to pass to function
*
*Return:
* void
*
*Exceptions:
* Input parameters are validated. Refer to the validation section of the function.
*
*******************************************************************************/
extern "C" _CRTIMP void __cdecl _CrtDoForAllClientObjects(
void (*pfn)(void *, void *),
void * pContext
)
{
_CrtMemBlockHeader * pHead;
/* validation section */
_VALIDATE_RETURN_VOID(pfn != NULL, EINVAL);
if (!(_crtDbgFlag & _CRTDBG_ALLOC_MEM_DF))
return; /* sorry not enabled */
_mlock(_HEAP_LOCK); /* block other threads */
__try {
for (pHead = _pFirstBlock; pHead != NULL; pHead = pHead->pBlockHeaderNext)
{
if (_BLOCK_TYPE(pHead->nBlockUse) == _CLIENT_BLOCK)
(*pfn)((void *) pbData(pHead), pContext);
}
}
__finally {
_munlock(_HEAP_LOCK); /* release other threads */
}
}
程序代码:
void group_compitition(Group_inform &group,Graph *g) { int i,j; double *probability_gap;//生成概率梯度 double *choice; //存放选择评判的数据 int *lable; //存放被选择个体的标号 int **family_tempt; srand((unsigned) time(NULL)); family_tempt=(int**)malloc(group_num*sizeof(int*)); for(i=0;i<group_num;i++) family_tempt[i]=(int*)malloc(g->vertex_num*sizeof(int)); probability_gap=(double*)malloc(g->edge_num*sizeof(double)); choice=(double*)malloc(group_num*sizeof(double)); lable=(int*)malloc(group_num*sizeof(int)); memset(choice,0,sizeof(choice)); /* .................................................生成适应度梯度; */ probability_gap[0]=group.probability[0]; for(i=1;i<group_num;i++) { probability_gap[i]=probability_gap[i-1]+group.probability[i]; } /* .................................................确定哪些成员生存, */ for(i=0;i<group_num;i++) choice[i]=rand()%100/100.0; for(i=0;i<group_num;i++) { for(j=0;j<group_num;j++) if(choice[i]<=probability_gap[j]) break; lable[i]=j; } for(i=0;i<group_num;i++) { printf("%d ",lable[i]); if(i%10==0) printf("\n"); } /* ...........................................使优良个体得以壮大不好的个体淘汰 */ for(i=0;i<group_num;i++) for(j=0;j<g->vertex_num;j++) family_tempt[i][j]=group.group_family[i][j]; for(i=0;i<group_num;i++) { printf("family:\n"); for(j=0;j<g->vertex_num;j++) { printf(" %d",family_tempt[i][j]); } printf("\ngroup:\n"); for(j=0;j<g->vertex_num;j++) { printf(" %d",group.group_family[i][j]); } printf("\n"); } for(i=0;i<group_num;i++) { for(j=0;j<g->vertex_num;j++) group.group_family[i][j]=family_tempt[lable[i]][j]; } free(lable); free(choice); free(probability_gap); for(i=0;i<group_num;i++) free(family_tempt[i]); free(family_tempt); }