I have been using BDS 2006 Turbo C ++ for a long time, and some of my large projects ( CAD / CAM, 3D gfx engines and astronomical calculations) sometimes throw an exception (for example, once every 3-12 months 24/7 use in severe conditions). After extensive debugging, I found this:
this code is usually inside the template, where _s can also be a class, so delete[] this code should work correctly, but delete[] does not work properly for structs (classes look OK). No exceptions are thrown, the memory is freed, but it somehow corrupts the distribution tables of the memory manager, and after that any new allocation may be incorrect (new ones may create overlapping allocations with already allocated space or even unallocated space, therefore, random exceptions)
I found that if I add an empty destructor to _s , than everything seems OK
struct _s { int i; ~_s(){}; }
Well, now comes the weird part. After I updated this in my projects, I found that the AnsiString class also has poor redistributions. For example:
This dat code contains some useful data, and then some txt line created by adding lines, so txt needs to be redistributed several times, and sometimes dat data is overwritten by txt (even if they don't overlap, I suppose the temp AnsiString needed to redistribute txt , overlaps with dat )
So my questions are:
PS
- these errors depend on the number of
new/delete/delete[] non-allocated uses - errors code1 and code2 are repeated (for example, the parser loads a complex ini file, and the error occurs on the same line if ini does not change)
- I find these errors only for large projects (simple source code> 1 MB) with a combined use of
AnsiString and templates with internal dynamic allocations, but it is possible that they are also in simpler projects, but are so rare that I miss. - Infected projects:
- win32 noinstall standalone (using Win7sp1 x64 , but on XPsp3 x32 it behaves the same)
- not taken into account when using GDI or OpenGl / GLSL
- does not measure if device DLL s driver is used or not
- no OCX or custom VCL component
- no DirectX
- 1 byte of aligned compilation / link
- do not use RTL , packages, or frameworks (stand-alone)
Sorry for the poor English / grammar ... any help / conclusion / suggestion appreciated.
memory-management struct ansistring c ++ builder
Spektre
source share