Re: Heap memory available (W32 console app in Visual C++)
Igor Tandetnik a ?crit :
Why not
p1 = malloc(wanted1);
if (p1) p2 = malloc(wanted2);
if (p1 && p2) {
// Process two blocks
} else {
if (p1) free(p1);
// switch to alternative method
}
Because it's much more complicated and less elegant than what I have now:
--------
struct rec *p1, *p2;
int numrecs1 = ...;
if ( ! ( p1 = (struct rec *)malloc( wanted1 + wanted2 ) )
// switch to alternative method
p2 = p1 + numrecs1;
// continue
--------
You seem to misunderstand how critical sections work. All threads
accessing the same shared data must do so under the same critical
section, otherwise it won't help any. You can't enforce proper access
synchronization from just one thread - all threads must cooperate.
You seem to have a different understanding of "critical sections" from me.
In my terms (as a low-level assembly language programmer, having written
a multi-tasking kernel) the start of a critical section is marked by a
mutex and until it is cleared no other thread can aquire the CPU.
During a critical section the question of co-operation and sharing data
therefore simply doesn't exist: that is the whole point.
Anyway, we still haven't determined whether the 'data' - the heap - is
really shared or not.
If one single process malloc()'s one byte (OK - it will probably take 4,
neatly aligned) is the entire Windows memory management system updated?
Now, how do you plan to get all other processes in the system to use
your critical section whenever they allocate memory?
I don't. Memory management under Windows doesn't seem to be very
intelligent and I can't fix that.
Of course not. But all processes do share the same physical memory chips
installed on the motherboard, and the same swap file on the same
physical hard drive.
So if there is not enough memory available to start a new process with
'normal' memory requirements, the system should say so immediately and
refuse.
--
bitwyse [PGP KeyID 0xA79C8F2C]
Les conseils - c'est ce qu'on demande quand on conna?t d?j? la r?ponse
mais aurait pr?f?r? ne pas la savoir.
http://www.le-maquis.net