Memory allocation overflow in c program

In a large system I try to allocate about 1GB of memory on a 4GB system

and it blows up (returns a NULL pointer in C), Now I tried to allocate

1GB from a small test program and it also returns null.

Also, I have implemented the /LARGEADDRESSLIMIT switch on the Linker,

to be able to address more than 2GB RAM. But the system does not want

to allocate 1GB, when the available memory is 1.8GB according to the

Task Manager!!

ex: BYTE *bb=(BYTE*) calloc(0.9, 0x40000000);
where BYTE is unsigned char

I can only allocate about 400MB, otherwise I get NULL

How much memory I can allocate from a C program ?

It looks like there is something I don't quite understand about the x86

memory model.

The limits are set by:
1. Available memory, obviously.
2. How fragmented memory is. Since an array has to reside in n adjacent bytes, if there are no n adjacent bytes available the allocation will fail, even if there are n or more bytes available total.
3. Operating system limitations. The compiler switch suggests you're compiling for Windows. The desktop 32-bit NT kernels enforce a 2 private GB limit for each program. I've also seen memory allocation failing at even lower margins, such as your case.

If you need to allocate that much memory, it's time to think about switching to a 64-bit kernel.
Topic archived. No new replies allowed.