Discussion:
Heap Allocation failure differ in WINXP/Vista and Windows 7
(too old to reply)
Kartlee
2011-01-19 19:23:38 UTC
Permalink
Raw Message
Hi,

In the below given code, WindowXP 32-bit fails for second allocation
( 768 MB ) but succeed for 256 MB thrice. In Windows 7, I see 768MB
and 768MB succeed but 256 MB allocations fail. Vista 32-bit show the
same behavior as XP.

Is there any difference in VirtualAlloc'd block of the help in XP and
Windows 7? Please explain.

I don't think the allocation failure is due to fragmentation. Please
correct if I am wrong.

#include<stdio.h>
#include<stdlib.h>
#include <windows.h>


int main(){
char *a, *b, *c, *d, *e, *f;

a = (char*)malloc(1024*1024*1024);
if(a)
fprintf(stderr, "Success\n");
else
fprintf(stderr, "Failed\n");



b = malloc(1024*1024*768);
if(b)
fprintf(stderr, "Success\n");
else
fprintf(stderr, "Failed\n");


c = malloc(1024*1024*256);
if(c)
fprintf(stderr, "Success\n");
else
fprintf(stderr, "Failed\n");



d = malloc(1024*1024*256);
if(d)
fprintf(stderr, "Success\n");
else
fprintf(stderr, "Failed\n");


e = malloc(1024*1024*256);
if(e)
fprintf(stderr, "Success\n");
else
fprintf(stderr, "Failed\n");


f = malloc(1024*1024*172);
if(f)
fprintf(stderr, "Success\n");
else
fprintf(stderr, "Failed\n");


return 0;
}

-Karthik
rogero
2011-01-24 09:24:27 UTC
Permalink
Raw Message
Post by Kartlee
I don't think the allocation failure is due to fragmentation. Please
correct if I am wrong.
Hello Karthik,
This article might help you understand what is going on:

http://www.howzatt.demon.co.uk/articles/OutOfMemory.html

Regards,
Roger.
Giggle
2011-01-26 01:28:34 UTC
Permalink
Raw Message
Good article!!! I'd learnt much from it. Thanks for your sharing.
Loading...