new TCHAR[..] and access violation

  • Thread starter Thread starter Alek
  • Start date Start date
A

Alek

sometimes a simple line code like

TCHAR *tRow = new TCHAR[tempSize];
cause an access violation.

What's problem?

My application is multithread, compiled in visual studio 7.0, unmanaged.

thanks for help

bye

Alek
 
Alek said:
sometimes a simple line code like

TCHAR *tRow = new TCHAR[tempSize];
cause an access violation.

What's problem?

The problem is, very likely, that your application has corrupted the heap by
over-indexing a heap allocation, or by modifying memory after you've
returned it to the heap (via delete or free).

The problem lies somewhere in your program - likely far away from the line
where the error is detected.

You might have better luck isolating the problem by running your application
under the full page heap. You can enable full-page heap for your
application by downloading & installing the latest Windows debuggers from

http://www.microsoft.com/whdc/ddk/debugging/default.mspx

and issue the command

c:\debuggers>gflags -i your_app.exe +hpa

from a command prompt (assuming you installed the debuggers into
c:\debuggers).

Note that the full-page heap won't detect all errors, because the VC++ CRT
does some of it's own heap management (holding onto larger blocks allocated
from the system heap and sub-allocating from those blocks).

-cd
 
good, but when I set

gflags -i your_app.exe +hpa

how can I see heap status ? where is it logged ?

thank you
bye

Carl Daniel said:
Alek said:
sometimes a simple line code like

TCHAR *tRow = new TCHAR[tempSize];
cause an access violation.

What's problem?

The problem is, very likely, that your application has corrupted the heap by
over-indexing a heap allocation, or by modifying memory after you've
returned it to the heap (via delete or free).

The problem lies somewhere in your program - likely far away from the line
where the error is detected.

You might have better luck isolating the problem by running your application
under the full page heap. You can enable full-page heap for your
application by downloading & installing the latest Windows debuggers from

http://www.microsoft.com/whdc/ddk/debugging/default.mspx

and issue the command

c:\debuggers>gflags -i your_app.exe +hpa

from a command prompt (assuming you installed the debuggers into
c:\debuggers).

Note that the full-page heap won't detect all errors, because the VC++ CRT
does some of it's own heap management (holding onto larger blocks allocated
from the system heap and sub-allocating from those blocks).

-cd
 
Alek said:
good, but when I set

gflags -i your_app.exe +hpa

how can I see heap status ? where is it logged ?

Run you app under a debugger and you'll see messages from the heap manager
(in the Output window is you're using Visual Studio).

-cd
 
Back
Top