: 1) I think that local (stack) and global variables also
: have guard bytes. However I cannot see any
: mechanism for detecting when an overwrite occurs.
: Does anybody know how to do it?
Stack pages are guarded for overflow and underflow. Reference Richter,
Programming Applications for Windows, pp. 559-569. ISBN 1-57231-996-8.
Basically, the pages are marked PAGE_GUARD, which allows application to
catch the exceptions generated on a write.
I don't know about heap guards (outside of synchronization, or queuing
of requests into the heap).
: 2) We are getting a memory access violation in
: release mode but never in debug mode.
Build the release with a map file and debug symbols. The map file will
be useful if a customer sends you a dump (you can't duplicate on
premises). Debug will be useful if you can duplicate and attach a
de{*filter*}.
A few of the fellows who answer questions have links on their sites
about release builds with debug info, and the infamous access violation
in release mode.
I also prefer to use BoundsChecker.
Jeff
When you build a project in debug mode, it uses the debug memory
allocator to
manage the heap. This means that all memory allocations have guard bytes
placed
around them. These guard bytes are used to detect errant memory
overwrites.
Various diagnostic routines can be turned on to report any problems. (eg
with
afxMemDF |= checkAlwaysMemDF and _heapchk() )
1) I think that local (stack) and global variables also have guard
bytes.
However I cannot see any mechanism for detecting when an overwrite
occurs. Does
anybody know how to do it?
2) We are getting a memory access violation in release mode but never in
debug
mode. I have tried disabling optimisation in the release mode but this
does not
stop the problem. I have enabled all the heap diagnostics while in
debug mode
(they cannot operate in release mode) and these have not thrown anything
up. I
would guess that the piece of code that overwrites memory could be far
away from
the code whose memory gets corrupted, so it sounds really tricky to
track down.
How would you solve this problem?
thanks