Are they the only heap initializers?
You mentioned having 2 heaps going on...
Yes, the other heap is initialized when needed (internally). I need __bheapinit() called very early, because the startup code needs to allocate some memory. The dependency on __bheapinit() is a bit messy, and should probably be removed in the future.
Ok... I have looked at the lib and the startup sequence... it looks like it's setting 2megs for the small heap and about 4k for the big one... I've found out where the initialization routines and heap calls etc. are (_bigheap.obj, _dflheap.obj and _getmem.obj) and I've had a look at the standard functions... I *think* I know what's going on.
I looks like I will need to replace bigheap.obj as well as the malloc, calloc, realloc and free standard functions. No problem... provided the other crt functions that call on the memory allocator call malloc instead of going directly to __bheap_alloc (etc.) I can probably even combine the whole thing into a single external lib.
The only thing that would stop me is if the small heap ends up wasting memory, even if it's never called... That would rather undo the whole idea, wouldn't it? I gather that I can prevent it from ever being called by writing it out of the malloc (etc.) produres and setting __bheap_threshold to 0?
The advantage of this method is that we can still use a dual heap memory manager... it will just be in a different library... OR if someone wants to write a garbage collector they can... OR... if someone wants to use local alloc and virtual alloc based management, they can... OR... It all depends what code they hide behind the standard calls...
If I can get this to work it would be possible to eliminate all memory management from the main CRT library and all you would need was a call to an external __bheap_init function to kick start whatever is in the memory manager library...
If this can be made to work, I may need to ask you to create a #pragma to let me explicitly call in outside managers. It could still default to your existing 2 tiered system, except that it would be in an external lib (eg."memmgr.lib") or through the pragma we could tell it to use a custom manager in a different lib (eg. #pragma memmgr "mymem.lib")
But before we do any of that there's the testing and hairpulling phase
Ok, one more question before I head off to make a mess of things -- err, I mean try this. If I do move those functions out to a separate lib, can I still use the same names... but replace their content. i.e. if they externally behave as expected the other functions that use them won't be grumbling at me, will they?
No problems - malloc() & friends are like any other functions - they just happen to have standardized names. What complicates things is that if you have more than one malloc() function, the linker will pick the first malloc() it finds - most likely from crt.lib.
Yeah that's what I'm worried about... beyond the matter of redundency it could cause some truly strange behaviour.
If you can find a way around this, with the proper use of #pragma nodefaultlib, and #pragma lib "my_memory_functions.lib" you might not even have to mess with pulling apart crt.lib...
Hmmm... interesting thought, but I can't see how I'd do that...
Are you thinking that so long as my lib is specified first then crt.lib after?
#pragma nodefaultlib
#pragama lib "mymm.lib"
#pragama lib "crt.lib"
Like that?
Bottom line: this require some time & testing...
No kidding... Looks like I've really stepped in it this time...
Since I'm messing with core functionality, you can bet I will be letting you see and test this before I ever put it to use...