BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

MM: What should be the maximum allocated size ?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Language BASM
View previous topic :: View next topic  
Author Message
Florent Ouchet
Guest





PostPosted: Tue May 10, 2005 5:20 pm    Post subject: MM: What should be the maximum allocated size ? Reply with quote



Hi,

What should be the maximum size that could be allocated at a time ?

Is it possible to get more than 2GB (2^31 Byte) in one call ? Can the
Microsoft's VirtualAlloc or HeapAlloc allocate this size ?

If it is not possible, it should be possible to use the last bit as a
free flag; and use the 31 lower bits to store the size.

TIA,

Florent
Back to top
Eric Grange
Guest





PostPosted: Tue May 10, 2005 6:18 pm    Post subject: Re: MM: What should be the maximum allocated size ? Reply with quote



Quote:
Is it possible to get more than 2GB (2^31 Byte) in one call ?

Not in 32 bit. It may theoretically be possible with the /3GB switch,
but in practice there will always be some memory allocated in the middle
of the virtual memory space, which means the largest contiguous block of
free memory is much smaller.
When you have 1 GB of contiguous space (and can allocate a 1 GB block),
you should already consider yourself very lucky.

Eric

Back to top
Avatar Zondertau
Guest





PostPosted: Tue May 10, 2005 6:48 pm    Post subject: Re: MM: What should be the maximum allocated size ? Reply with quote



Quote:
Is it possible to get more than 2GB (2^31 Byte) in one call ?

Not in 32 bit. It may theoretically be possible with the /3GB switch,
but in practice there will always be some memory allocated in the
middle of the virtual memory space, which means the largest
contiguous block of free memory is much smaller. When you have 1 GB
of contiguous space (and can allocate a 1 GB block), you should
already consider yourself very lucky.

This is really easy to test. Though results may vary slightly this will
give an indication:



function FindMaxAllocSize: LongWord;
var
Avg, Max, Min: LongWord;
Mem: Pointer;
begin
Min := $00000000;
Max := $80000000;
while Min < Max do
begin
Avg := (Min + Max + 1) div 2;
Mem := VirtualAlloc(nil, Avg, MEM_RESERVE, PAGE_NOACCESS);
if Mem = nil then
Max := Avg - 1
else
begin
VirtualFree(Mem, 0, MEM_RELEASE);
Min := Avg;
end;
end;
Result := Min;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage('You can allocate 0x' + IntToHex(FindMaxAllocSize, Cool +
' bytes');
end;



My result:

You can allocate 0x45160000 bytes

This is more that 1.1 GB.

Back to top
Florent Ouchet
Guest





PostPosted: Tue May 10, 2005 6:58 pm    Post subject: Re: MM: What should be the maximum allocated size ? Reply with quote

Quote:
You can allocate 0x45160000 bytes

This is more that 1.1 GB.

The limit on my computer is $3F330000 (1060306944 Bytes). (Windows 2000
Pro SP4, 512MB RAM, 512MB Swap).

It may be interesting if you tell us your physical and virtual memory sizes.

TIA,

Florent

Back to top
Florent Ouchet
Guest





PostPosted: Tue May 10, 2005 7:05 pm    Post subject: Re: MM: What should be the maximum allocated size ? Reply with quote

Quote:
The limit on my computer is $3F330000 (1060306944 Bytes). (Windows 2000
Pro SP4, 512MB RAM, 512MB Swap).

Really interesting, I just opened my eyes and saw that it is possible to
reserve more memory than available (Windows, Mozilla and Delphi should
use more than 100Mb)...

Florent

Back to top
Avatar Zondertau
Guest





PostPosted: Tue May 10, 2005 7:19 pm    Post subject: Re: MM: What should be the maximum allocated size ? Reply with quote

Quote:
The limit on my computer is $3F330000 (1060306944 Bytes). (Windows
2000 Pro SP4, 512MB RAM, 512MB Swap).

Windows XP Pro, 512 MB RAM, swap file 765 MB.

Quote:
Really interesting, I just opened my eyes and saw that it is possible
to reserve more memory than available (Windows, Mozilla and Delphi
should use more than 100Mb)...

The memory is only being reserved, not commited. You should try and see
what happens if you change that parameter to make it commit.

I guess you'll be getting a "Windows is running low on memory, please
close programs or increase swap size" message. The reservation is seems
to be mostly used for keeping the virtual address space free, not for
making sure the memory is actually available.

Back to top
Avatar Zondertau
Guest





PostPosted: Tue May 10, 2005 7:21 pm    Post subject: Re: MM: What should be the maximum allocated size ? Reply with quote

Quote:
Really interesting, I just opened my eyes and saw that it is
possible to reserve more memory than available (Windows, Mozilla
and Delphi should use more than 100Mb)...

The memory is only being reserved, not commited. You should try and
see what happens if you change that parameter to make it commit.

It turns out for me the maximum commit size equals the maximum reserve
size. Would it perhaps only really commit on the first write?

Back to top
Eric Grange
Guest





PostPosted: Wed May 11, 2005 7:58 am    Post subject: Re: MM: What should be the maximum allocated size ? Reply with quote

Quote:
Would it perhaps only really commit on the first write?

On the first access to a page (read or write) it will start using "real"
memory (either RAM or SWAP) for that page.

Eric

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Language BASM All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.