루프를 사용하여 파일에 매개 변수를 쓰는 출력 함수가 있습니다. 내가 충돌하기 전에 여러 번 함수를 호출하고 제대로 작동합니다. 루프는 "count"매개 변수에 지정된 시간을 반환합니다. 카운트가 6000이면 5960에서 충돌합니다.이 함수는 이전 호출에서 충돌하지 않으며 함수에 더 적은 수를 전달합니다.C++에서 flsgetvalue() 힙 손상을 해결하는 방법은 무엇입니까?
오류가 날 tidtable.c를 의미하고 선 포인트 :
template <typename T>
T *AllocateDynamicVector(int nRows){
T *dynamicArray;
dynamicArray = new T[nRows];
for(int i = 0 ; i < nRows ; i++){
dynamicArray[i]= 0;
}
return dynamicArray;
}
초기화 : 나는 다음과 같은 템플릿을 사용하여 함수에 PNTR 유일한 동적으로 할당 된 매개 변수를 초기화
_CRTIMP PFLS_GETVALUE_FUNCTION __cdecl __set_flsgetvalue()
{
#ifdef _M_IX86
PFLS_GETVALUE_FUNCTION flsGetValue = FLS_GETVALUE; // <---exactly Here
if (!flsGetValue)
{
flsGetValue = DecodePointer(gpFlsGetValue);
TlsSetValue(__getvalueindex, flsGetValue);
}
return flsGetValue;
을 메인에서 :
int* pntrPlane = AllocateDynamicVector<int>(2*numberOfCells);
Writer(myfile,ss,"123","0","0","1","0","0","0","1","0",2*numberOfCells,lineInfo,1,pntrPlane);
코드는 아래에 있습니다 :
void Writer (ofstream &myfile, stringstream &ss, std::string type, std::string id1, std::string id2, std::string id3,
std::string id4,std::string id5,std::string id6,std::string id7,std::string id8, int count,
int lineInfo[2], int lineNum, int* pntr){
if(myfile.is_open()){
for (int i=0; i < count; i++){
if (type == "123"){
cout<<"I'm here!"<<" "<<i<<endl;
}
ss.seekp(0);
ss<<setw(80)<<lineInfo[0]; ss.seekp(0);
ss<<setw(73)<<"1D"; ss.seekp(0);
ss<<setw(56)<<id1.c_str(); ss.seekp(0);
ss<<setw(48)<<id2.c_str(); ss.seekp(0);
ss<<setw(40)<<id3.c_str(); ss.seekp(0);
ss<<setw(32)<<id4.c_str(); ss.seekp(0);
ss<<setw(24)<<id5.c_str(); ss.seekp(0);
ss<<setw(16)<<lineInfo[1]; ss.seekp(0);
ss<<setw(8)<<type.c_str(); ss.seekp(0);
myfile<<ss.str()<<endl; ss.clear();
pntr[i] = lineInfo[0];
lineInfo[0]++;
ss.seekp(0);
ss<<setw(80)<<lineInfo[0]; ss.seekp(0);
ss<<setw(73)<<"0D"; ss.seekp(0);
ss<<setw(40)<<id6.c_str(); ss.seekp(0);
ss<<setw(32)<<lineNum; ss.seekp(0);
ss<<setw(24)<<id8.c_str(); ss.seekp(0);
ss<<setw(16)<<"0"; ss.seekp(0);
ss<<setw(8)<<type.c_str(); ss.seekp(0);
myfile<<ss.str()<<endl; ss.clear();
lineInfo[0]++;
lineInfo[1] = lineInfo[1] + lineNum;
}
}
}
어떻게하면 문제를 피할 수 있습니까 ??
참고 : 디버깅하지 않고 프로그램을 실행하면 오류가 사라집니다.
편집 : 문제에 대한 자세한 설명 : 위의 기능을 여러 번 사용하여 출력 파일을 생성 중입니다. 동적 정수 벡터를 포함하여 함수에 매개 변수를 보내고 반복 할 때마다 숫자를 씁니다. 매개 변수 집합을 사용하여이 함수를 실행하는 동안 힙 손상 오류 "Critical error detected c0000374"가 발생합니다. 이상한 것들은 다른 인스턴스에 오류를주지 않는다는 것입니다.
오류에 대해 자세히 설명해 주실 수 있습니까? 그리고 전체 코드도 게시 할 수 있습니까? (어딘가에?) –
@ C Johnson 최후에 세부 사항을 더 추가하려고했습니다. 고맙습니다. –