Click to See Complete Forum and Search --> : Can I malloc a space larger than 3G bytes?
warrener
May 19th, 2008, 01:07 AM
We know that a process memory space is limited by 4G (1G for kernel).
I am thinking if I can malloc a space larger than 3G. So I tried the following:
int main()
{
char* x = (char*)malloc(3*1024*1024*1024);
return 0;
}
AND It works! ....
Anybody knows why?
I also tried
char x[0x7fffffff];
This time compiler complains for its size. So I guess the implementations of malloc and char[] are different, right?
DraculaW
May 19th, 2008, 03:18 AM
Yes, the char [] alloc mem from stack and malloc from heap.
Because you cannot alloc a mem from stack which is large than stack,
if you wanna alloc a large mem pls look you compile manual to find out how to adjust stack size.
hujing
May 19th, 2008, 09:29 AM
virtual memeroy alloction
Lindley
May 19th, 2008, 09:37 AM
How much you can malloc depends on a number of factors:
1) Whether your OS is 32-bit or 64-bit
2) How much memory is in your graphics card
3) Whether or not you have virtual memory
etc.
Ajay Vijay
May 19th, 2008, 11:08 AM
First thing first, 3GB (or 2GB) user space does NOT mean that you can allocate it as single chunk of bytes. The system may not (most probably) have that large 'single' chunk of bytes.
You may have to loop for multiple allocations.
On Windows, new and malloc are slow. You should use HeapAlloc for moderate allocation (around 500B to few KBs). For larger allocations you can use VirtualAlloc, do memory mappping (to actually play with pointers). Even then you CANNOT have more than 2/3 GB alloaction for your process.
For this, On 32-bit systems you can use PAE - Physical Address Extension. On Windows you can achieve the same by using AWE library. Look at MSDN.
On 64-bit platform, you must have that much of physical and/or virtual memory.
kenrus
May 20th, 2008, 10:11 AM
How much you can malloc depends on a number of factors:
1) Whether your OS is 32-bit or 64-bit
2) How much memory is in your graphics card
3) Whether or not you have virtual memory
etc.
The memory on your graphics card affects the amount of memory you can allocate?
GNiewerth
May 20th, 2008, 10:21 AM
That´s true for Windows XP 32bit. The uppermost GB (>3) is reserved for I/O mapping, the more RAM you have on your graphics adapter the more space is required to map that RAM into Windows´ address space.
Ajay Vijay
May 20th, 2008, 11:16 AM
That´s true for Windows XP 32bit. The uppermost GB (>3) is reserved for I/O mapping, the more RAM you have on your graphics adapter the more space is required to map that RAM into Windows´ address space.Not that way.
Default is 2 GB Kernel + 2 GB User space. 1GB Kernel and 3 GB user space is applicable to a process only when following conditions are met:
1. System is started with /3G parameter in BOOT.INI file.
2. The image (.EXE) is linked with /LARGEADDRESSAWARE option.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.