Re: Memory Management
- From: "Carl Daniel [VC++ MVP]" <cpdaniel_remove_this_and_nospam@xxxxxxxxxxxxxxx>
- Date: Sun, 18 Jun 2006 22:09:09 -0700
Klaus Hartmann wrote:
Hi everyone,
I have implemented a memory manager for some SDK I'm working on (a
game engine). The primary goal of this memory manager is to reduce
fragmentation, to perform fast allocation of small blocks of memory,
and to give more detailed information about memory leaks. This
manager works fine, and without problems.
Now, as you might have guessed already, my problems are the operators
new and delete. I wish to overload them in a *safe* way, such that
the memory manager is automatically used. I do not want to use
class-based new/delete operators. It also has to work properly with
other libraries, including the STL. I did overwrite the global
operators, and that woks, but it just doesn't feel safe.
I realize that there's a good chance, that you'll tell me, that
there's just no good and safe way to do what I want. But maybe I'm
wrong, and someone here's got this great idea :-) There's just got to
be some way to write a cusom memory manager.
IF you're using VC++ (which presumably you are, since you're posting here),
and IF your program is monolithic (not a collection of DLLs), then you can
simply provide your own definition of the malloc family of fine functions
and all C and C++ memory allocations will go through your code, including
new, new[], std::allocator, etc.
If you're building a program out of a bunch of DLLs, then it's a bit harder,
but there's still a reasonably clean solution: put your rmemory manager in
a DLL of it's own, supplying malloc (free, etc) and global operator
new/new[]/delete/delete[] as exports from your DLL. Link the import library
for your memory manager with the main executable and all the other DLLs,
making sure that the linker sees your import library before the C/C++
runtime libraries.
-cd
.
- Follow-Ups:
- Re: Memory Management
- From: Klaus Hartmann
- Re: Memory Management
- References:
- Memory Management
- From: Klaus Hartmann
- Memory Management
- Prev by Date: Need mod operator as VB
- Next by Date: Re: Need mod operator as VB
- Previous by thread: Memory Management
- Next by thread: Re: Memory Management
- Index(es):
Relevant Pages
|