📄 object.cxx
字号:
if (memcmp((char *)(obj+1)+obj->size, obj->GuardBytes, sizeof(obj->guard)) != 0) { if (error != NULL) *error << "Overrun at " << (obj+1) << '[' << obj->size << "] #" << obj->request << endl; return FALSE; } obj = obj->next; }#if defined(_WIN32) && defined(_DEBUG) if (!_CrtCheckMemory()) { if (error != NULL) *error << "Heap failed MSVCRT validation!" << endl; return FALSE; }#endif if (error != NULL) *error << "Heap passed validation." << endl; return TRUE;}BOOL PMemoryHeap::SetIgnoreAllocations(BOOL ignore){ Wrapper mem; BOOL ignoreAllocations = (mem->flags&NoLeakPrint) != 0; if (ignore) mem->flags |= NoLeakPrint; else mem->flags &= ~NoLeakPrint; return ignoreAllocations;}void PMemoryHeap::DumpStatistics(){ Wrapper mem; if (mem->leakDumpStream != NULL) mem->InternalDumpStatistics(*mem->leakDumpStream);}void PMemoryHeap::DumpStatistics(ostream & strm){ Wrapper mem; mem->InternalDumpStatistics(strm);}void PMemoryHeap::InternalDumpStatistics(ostream & strm){ strm << "\nCurrent memory usage: " << currentMemoryUsage << " bytes"; if (currentMemoryUsage > 2048) strm << ", " << (currentMemoryUsage+1023)/1024 << "kb"; if (currentMemoryUsage > 2097152) strm << ", " << (currentMemoryUsage+1048575)/1048576 << "Mb"; strm << ".\nCurrent objects count: " << currentObjects << "\nPeak memory usage: " << peakMemoryUsage << " bytes"; if (peakMemoryUsage > 2048) strm << ", " << (peakMemoryUsage+1023)/1024 << "kb"; if (peakMemoryUsage > 2097152) strm << ", " << (peakMemoryUsage+1048575)/1048576 << "Mb"; strm << ".\nPeak objects created: " << peakObjects << "\nTotal objects created: " << totalObjects << "\nNext allocation request: " << allocationRequest << '\n' << endl;}DWORD PMemoryHeap::GetAllocationRequest(){ Wrapper mem; return mem->allocationRequest;}void PMemoryHeap::SetAllocationBreakpoint(DWORD point){ allocationBreakpoint = point;}void PMemoryHeap::DumpObjectsSince(DWORD objectNumber){ Wrapper mem; if (mem->leakDumpStream != NULL) mem->InternalDumpObjectsSince(objectNumber, *mem->leakDumpStream);}void PMemoryHeap::DumpObjectsSince(DWORD objectNumber, ostream & strm){ Wrapper mem; mem->InternalDumpObjectsSince(objectNumber, strm);}void PMemoryHeap::InternalDumpObjectsSince(DWORD objectNumber, ostream & strm){ BOOL first = TRUE; for (Header * obj = listHead; obj != NULL; obj = obj->next) { if (obj->request < objectNumber || (obj->flags&NoLeakPrint) != 0) continue; if (first && isDestroyed) { *leakDumpStream << "\nMemory leaks detected, press Enter to display . . ." << flush;#if !defined(_WIN32) cin.get();#endif first = FALSE; } BYTE * data = (BYTE *)&obj[1]; if (obj->fileName != NULL) strm << obj->fileName << '(' << obj->line << ") : "; strm << '#' << obj->request << ' ' << (void *)data << " [" << obj->size << "] "; if (obj->className != NULL) strm << '"' << obj->className << "\" "; strm << '\n' << hex << setfill('0') << PBYTEArray(data, PMIN(16, obj->size), FALSE) << dec << setfill(' ') << endl; }}#else // PMEMORY_CHECK#ifndef P_VXWORKS/*#if (__GNUC__ >= 3) || ((__GNUC__ == 2)&&(__GNUC_MINOR__ >= 95)) //2.95.X & 3.Xvoid * operator new[](size_t nSize) throw (std::bad_alloc)#elsevoid * operator new[](size_t nSize)#endif{ return malloc(nSize);}#if (__GNUC__ >= 3) || ((__GNUC__ == 2)&&(__GNUC_MINOR__ >= 95)) //2.95.X & 3.Xvoid operator delete[](void * ptr) throw ()#elsevoid operator delete[](void * ptr)#endif{ free(ptr);}*/#endif // !P_VXWORKS#endif // PMEMORY_CHECK///////////////////////////////////////////////////////////////////////////////// Large integer support#ifdef P_NEEDS_INT64void PInt64__::Add(const PInt64__ & v){ unsigned long old = low; high += v.high; low += v.low; if (low < old) high++;}void PInt64__::Sub(const PInt64__ & v){ unsigned long old = low; high -= v.high; low -= v.low; if (low > old) high--;}void PInt64__::Mul(const PInt64__ & v){ DWORD p1 = (low&0xffff)*(v.low&0xffff); DWORD p2 = (low >> 16)*(v.low >> 16); DWORD p3 = (high&0xffff)*(v.high&0xffff); DWORD p4 = (high >> 16)*(v.high >> 16); low = p1 + (p2 << 16); high = (p2 >> 16) + p3 + (p4 << 16);}void PInt64__::Div(const PInt64__ & v){ long double dividend = high; dividend *= 4294967296.0; dividend += low; long double divisor = high; divisor *= 4294967296.0; divisor += low; long double quotient = dividend/divisor; low = quotient; high = quotient/4294967296.0;}void PInt64__::Mod(const PInt64__ & v){ PInt64__ t = *this; t.Div(v); t.Mul(t); Sub(t);}void PInt64__::ShiftLeft(int bits){ if (bits >= 32) { high = low << (bits - 32); low = 0; } else { high <<= bits; high |= low >> (32 - bits); low <<= bits; }}void PInt64__::ShiftRight(int bits){ if (bits >= 32) { low = high >> (bits - 32); high = 0; } else { low >>= bits; low |= high << (32 - bits); high >>= bits; }}BOOL PInt64::Lt(const PInt64 & v) const{ if ((long)high < (long)v.high) return TRUE; if ((long)high > (long)v.high) return FALSE; if ((long)high < 0) return (long)low > (long)v.low; return (long)low < (long)v.low;}BOOL PInt64::Gt(const PInt64 & v) const{ if ((long)high > (long)v.high) return TRUE; if ((long)high < (long)v.high) return FALSE; if ((long)high < 0) return (long)low < (long)v.low; return (long)low > (long)v.low;}BOOL PUInt64::Lt(const PUInt64 & v) const{ if (high < v.high) return TRUE; if (high > v.high) return FALSE; return low < high;}BOOL PUInt64::Gt(const PUInt64 & v) const{ if (high > v.high) return TRUE; if (high < v.high) return FALSE; return low > high;}static void Out64(ostream & stream, PUInt64 num){ char buf[25]; char * p = &buf[sizeof(buf)]; *--p = '\0'; switch (stream.flags()&ios::basefield) { case ios::oct : while (num != 0) { *--p = (num&7) + '0'; num >>= 3; } break; case ios::hex : while (num != 0) { *--p = (num&15) + '0'; if (*p > '9') *p += 7; num >>= 4; } break; default : while (num != 0) { *--p = num%10 + '0'; num /= 10; } } if (*p == '\0') *--p = '0'; stream << p;}ostream & operator<<(ostream & stream, const PInt64 & v){ if (v >= 0) Out64(stream, v); else { int w = stream.width(); stream.put('-'); if (w > 0) stream.width(w-1); Out64(stream, -v); } return stream;}ostream & operator<<(ostream & stream, const PUInt64 & v){ Out64(stream, v); return stream;}static PUInt64 Inp64(istream & stream){ int base; switch (stream.flags()&ios::basefield) { case ios::oct : base = 8; break; case ios::hex : base = 16; break; default : base = 10; } if (isspace(stream.peek())) stream.get(); PInt64 num = 0; while (isxdigit(stream.peek())) { int c = stream.get() - '0'; if (c > 9) c -= 7; if (c > 9) c -= 32; num = num*base + c; } return num;}istream & operator>>(istream & stream, PInt64 & v){ if (isspace(stream.peek())) stream.get(); switch (stream.peek()) { case '-' : stream.ignore(); v = -(PInt64)Inp64(stream); break; case '+' : stream.ignore(); default : v = (PInt64)Inp64(stream); } return stream;}istream & operator>>(istream & stream, PUInt64 & v){ v = Inp64(stream); return stream;}#endif#ifdef P_TORNADO// the library provided with Tornado 2.0 does not contain implementation // for the functions defined below, therefor the own implementationostream & ostream::operator<<(PInt64 v){ return *this << (long)(v >> 32) << (long)(v & 0xFFFFFFFF);}ostream & ostream::operator<<(PUInt64 v){ return *this << (long)(v >> 32) << (long)(v & 0xFFFFFFFF);}istream & istream::operator>>(PInt64 & v){ return *this >> (long)(v >> 32) >> (long)(v & 0xFFFFFFFF);}istream & istream::operator>>(PUInt64 & v){ return *this >> (long)(v >> 32) >> (long)(v & 0xFFFFFFFF);}#endif // P_TORNADO// End Of File ///////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -