M
Matthias =?ISO-8859-1?Q?K=E4ppler?=
For example, if you want to track memory allocations. I have seen custom
implementations of new and delete which worked like this:
1) Create a class MemInfo which holds information about the memory and data
type you're about to allocate.
2) When new is called: Instantiate MemInfo with type T and store it right
before the object you actually want to create on the heap. Move the address
pointer by sizeof(mem_obj). Allocate space for the actual object and store
it. Return its address.
3) When delete is called: Analogous to 2), but vice versa (deallocate,
subtract sizeof(mem_inf) from address pointer, deallocate mem_inf and
return.
implementations of new and delete which worked like this:
1) Create a class MemInfo which holds information about the memory and data
type you're about to allocate.
2) When new is called: Instantiate MemInfo with type T and store it right
before the object you actually want to create on the heap. Move the address
pointer by sizeof(mem_obj). Allocate space for the actual object and store
it. Return its address.
3) When delete is called: Analogous to 2), but vice versa (deallocate,
subtract sizeof(mem_inf) from address pointer, deallocate mem_inf and
return.