Dynamic Memory Allocation tracking and checking library
V1.0 - 08-June-1996
-------------------------------------------------------
Richard Harrison  - tricky@cix.compulink.co.uk

It is shareware, but it won't nag you, however if it helps
you find a bug, then it really is worth the measly 7 UKpounds to
register. 
-------------------------------------------------------

Description:
------------

This is a mini version of bounds-checker. I originally wrote it for use
in C, so it doesn't handle the cosmetic side of things so well in C++. 
Still it is probably the most useful thing, in terms of debugging aids, that
I've ever written, finding numerous bugs by its vigilance.

What it does is to provide replacements for the standard C runtime
allocation routines. The replacements track all allocations, provide
error notification when your program does something naughty. 

Currently it will tell you:

 - When freeing non-allocated memory
 - When you overwite past the beginning or end of an allocated glock
 - How much memory is in use
 - Where the memory is being used (which modules & lines)

It aids finding of leaks, by having a function which will dump memory
usage to a file, so you can do this before and after an operation which
should allocate and free some memory, and it is plainly visible if it
hasn't freed. 

Also, when you free memory it fills all free'd & delete'd blocks with
0xfe to prevent possible usage after free, and you will not be able to
use it.

How to use it - C.
------------------
#include "dyn_val.h" at the top of each module, or in a common header file.
When compiling for release it will not do anything. 

When building a debug version one of the following pre-processor symbols
should be defined (Note the VC IDE usually does this for you):

DEBUG
_DEBUG
DV_DYN_VAL

Link with one of the following

w32\dyn_val.lib   - VC4, VC2
w16\ldyn_val.lib  - VC1.5 Large model
w16\mdyn_val.lib  - VC1.5 Medium model
w16\sdyn_val.lib  - VC1.5 Small model

Provide a function called DV_error_log to log any errors which occur:

Typically:

#include <stdarg.h>
#include <stdio.h>
int DV_error_log (char *fmt, ...)
{

    char buf [500];
    va_list ap;

    va_start(ap, fmt);
    vsprintf(buf, fmt, ap);
    va_end(ap);

    puts(buf);
    return 0;
}

You may want to add a button/keyword (etc.) and call DV_ov_check_memory(), 
so you can test for overwrites.

You may want to add a button/keyword (etc.) and call DV_dump_memory()
so you can dump information about all the current allocated memory.

You may want to call DV_get_dynamic_memory_usage() To find out the amount 
(in bytes) of dynamic memory in use

Also, if you have an event look, then it doesn't hurt to call DV_scan_check_memory()
as this will check every second for overwrites, so you generally find out much 
earlier.

How to use it - C++.
------------------
As for C, except if you define DV_error_log in a C++ module then you'll
need to surrounding it with an extern "C"{}.

The way that it integrates with C++ is different than with C (C uses #define).
This means that you don't get the nice module information so either have a 
NEW_MARK before each new, new_set_id to mark a block of statements. Still the
good news is that it still helps identify bad usage, it just doesn't help
much to track them down. Any bright ideas gratefully received.

------------------------Reference Section----------------------------------

Standard Functions remapped - C:
--------------------------------
calloc
realloc
malloc
free
savestr
strdup
tempnam
tmpnam

Overloaded Operators - C++
--------------------------
new
delete


Functions
----------

Name:       DV_ov_check_memory
Purpose:    Check memory for overwrites
Parameters: None


Name:       DV_get_dynamic_memory_usage
Purpose:    Return the amount (in bytes) of dynamic memory in use
Parameters: None


Name:       DV_scan_check_memory 
Purpose:    Check memory for overwrites, call as often as required
            (e.g. in an event loop) as it will only check every second
Parameters: None

Name:       DV_dump_memory 
Purpose:    Output to a file, all memory currently allocated
            Writes to file memory%d.usage, where %d is a number
	    starting at starts at 1 and increments every time called.
            Useful for spotting leaks.
Parameters: None

Name:       DV_new_set_id
Purpose:    Marker for C++

