2. Common runtime error 2.1 terminate called after throwing an instance of 'std: bad_alloc'
The following error occurs: MyProgramThis occurs only when the data volume is too large. Analyzed to confirm the previous issuesCodeFrequently use new to generate an array, and then use Delete [] to delete it. Finally, modify it to declare an array (my program only needs one read/write buffer zone ):
Terminate called after throwing an instance of 'std: bad_alloc 'What (): STD: bad_allocaborted
2.2 free (): Invalid next size (FAST)
Improper malloc generation:
* ** Glibc detected **./p_main: Free (): Invalid next size (FAST): 0x08cec800 ***
In my case, declaring a char pointer to store data does not take '0' at the end into account, so the free release error occurs:
Tmpdir = (char *) malloc (strlen (DIR) + 1 + 1); strcpy (tmpdir, DIR); If (tmpdir [strlen (tmpdir)-1]! = '/') Strcat (tmpdir ,"/");
my summary: If malloc () is frequently used in a thread, even if it is free (), this will also lead to errors, or segment errors, otherwise, terminate called after throwing an instance of 'std: bad_alloc 'and other strange errors. I will not be able to use malloc () frequently. Stay. Frequent: malloc () is frequently called in programs. 2. When writing files, do not write strings to the files. Otherwise, it will lead you up. Oh. I will go. Regulatory