Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: OT: How to alloc large memory size (in Windows)?

Author: Eugene Nalimov

Date: 15:47:53 01/31/04

Go up one level in this thread


On January 31, 2004 at 18:22:11, Pham Hong Nguyen wrote:

>Hi all,
>
>I have been working on generating endgame databases and want to alloc some large
>blocks of memory (without exceeding 2 Gb - I know 2 Gb is the limitation for a
>Windows program).
>
>The program for testing is quite simple as the following (written in VC++):
>
>int main()
>{
>// Few init here
>int tbsize = 800000000; // 800 Mb
>HGLOBAL hg1 = GlobalAlloc(GHND, tbsize); ASSERT(hg1);
>HGLOBAL hg2 = GlobalAlloc(GHND, tbsize); ASSERT(hg2);
>}
>
>
>It work well if I set tbsize <= 660 000 000 (660 Mb, total size is 1.3 Gb), but
>the second assert fails if tbsize from 670 Mb. GetLastError() says: "Not enough
>storage is available to process this command". However, I think my machine has
>enough memory (Win2k, 2 Gb RAM, 20 available HDD, runing only this test
>program).
>
>I did some other tries:
>- Adding 512 Mb RAM (so my machine now has 2.5 Gb RAM)
>- Using VirtualAlloc instead of GlobalAlloc
>
>Unfortunately, the situation is still the same: 660 Mb ok, 670 Mb fails (not
>gain any more) and same message of GetLastErr().
>
>So, do you know why and how to solve this problem?
>Any help is highly appreciated.
>
>+Pham

First, Windows NT/2k/XP allows your program to use 3Gb of address space. Search
www.msdn.com for /3Gb and /LARGEADDRESSAWARE switches.

I believe your problem is caused by the fact that one or more of DLLs your
program is using is loaded in the middle of your address space. I.e. without any
special switches your application can use only addresses in the 0..0x7FFFFFFF
range. If one of DLLs will be loaded at address 0x10000000, you will not be able
to obtain a continious gigabyte of address space. If 3 DLLs will be loaded at
addresses 0x08000000, 0x10000000, and 0x18000000 than you'll be able to obtain
only ~512Mb of continious of address space.

On 32-bit platforms I am allocating several 100Mb blocks of RAM, and using
2-level indexing to get an exact address. This way I can use almost all 3Gb of
address spce when necessary.

Thanks,
Eugene



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.