|
-
May 19th, 2008, 01:07 AM
#1
Can I malloc a space larger than 3G bytes?
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:
Code:
int main()
{
char* x = (char*)malloc(3*1024*1024*1024);
return 0;
}
AND It works! ....
Anybody knows why?
I also tried
Code:
char x[0x7fffffff];
This time compiler complains for its size. So I guess the implementations of malloc and char[] are different, right?
-
May 19th, 2008, 03:18 AM
#2
Re: Can I malloc a space larger than 3G bytes?
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.
-
May 19th, 2008, 09:29 AM
#3
Re: Can I malloc a space larger than 3G bytes?
virtual memeroy alloction
-
May 19th, 2008, 09:37 AM
#4
Re: Can I malloc a space larger than 3G bytes?
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.
-
May 19th, 2008, 11:08 AM
#5
Re: Can I malloc a space larger than 3G bytes?
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.
-
May 20th, 2008, 10:11 AM
#6
Re: Can I malloc a space larger than 3G bytes?
 Originally Posted by Lindley
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?
John 3:16
For God so loved the world ...
-
May 20th, 2008, 10:21 AM
#7
Re: Can I malloc a space larger than 3G bytes?
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.
- Guido
-
May 20th, 2008, 11:16 AM
#8
Re: Can I malloc a space larger than 3G bytes?
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|