Memory Limit

Just starting out? Need help? Post your questions and find answers here.
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Memory Limit

Post by charvista »

Hi

I have a computer with a total of 12 GB of RAM. Yet I was very surprised to see that I seem unable to get over about 1.7 GB. Then I searched the forum and could read somewhere that ABBKlaus said that the limit is around 2 GB.
Is there a way to bypass this limit, to load say 3 GB in the Memory in one block? Otherwise I don't understand why computers have more than 2 GB, if no more can be used ????
Furthermore, I do not see any change in Memory usage in the Processes of the Windows' Task Manager.

Thanks for any light that might clarify my brain (which certainly has still an XT-like memory :mrgreen:)

And I have written a little program to test the memory allocation. It should clone a file's contents 1000 times. With small files, there would be no problem, but with big files, it will stop before reaching 1000:

Code: Select all

EnableExplicit

Procedure.i Test(Array *F(1),Array M(1),i)
If *F(i)=0
    MessageRequester("Error","Unable To allocate Memory at attempt #"+Str(i),0)
    ProcedureReturn 1
EndIf
ProcedureReturn 0
EndProcedure

Define.s FileName
Define.i Bin,Count,FileSize,i,Occ,Problem
Define.q Tmu

Occ=1000

Dim *F(Occ)
Dim M.i(Occ)

FileName=OpenFileRequester("Select a file","C:\","*.*",0)
Bin=OpenFile(#PB_Any,FileName)
FileSize=Lof(Bin)

For i=1 To Occ
    *F(i)=AllocateMemory(FileSize)
    Problem=Test(*F(),M(),i)
    If Problem
        Break
    Else
        Tmu=Tmu+FileSize
        Count=Count+1
    EndIf
Next i

For i=1 To Occ
If M(i) : ReadData(Bin,*F(i),FileSize) : EndIf
Next i

MessageRequester("Result","Total Size successufully loaded into Memory: "+Str(Tmu)+" bytes."+#CRLF$+#CRLF$+FileName+#CRLF$+#CRLF$+"could be loaded in memory "+Str(Count)+" time(s).",0)

End; memory is automatically freed
Edit: Tested with 32-bit PureBasic 5.20
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Re: Memory Limit

Post by ABBKlaus »

I sayd its true on x86 compiled applications ;-)

http://msdn.microsoft.com/en-us/library ... s.85).aspx
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: Memory Limit

Post by charvista »

Wow, what a fast reply! And by you in person, dear ABBKlaus! :wink:
Interesting page. So there are indeed limits, depending on the computer architecture, the version and subversion of Windows! Why not making it universal?! But ok, that's Bill Gates' choice.

My problem is that I am not a API-man, and I do not understand very well what Microsoft means by:
Limits on memory and address space vary by platform, operating system, and by whether the IMAGE_FILE_LARGE_ADDRESS_AWARE value of the LOADED_IMAGE structure and 4-gigabyte tuning (4GT) are in use. IMAGE_FILE_LARGE_ADDRESS_AWARE is set or cleared by using the /LARGEADDRESSAWARE linker option.
Does it mean that we can bypass this with an API flag on file open? If possible, a small example would be fine, so I know how to make my programs compatible with 32bits and 64bits.

By the way, I tested it now on a 64-bits machine with Windows 8.1 Pro and it reached 48 GB, which is already much better :)
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Memory Limit

Post by davido »

In theory a 32 bit operating system can only address 2^32 = 4,294,967,296 (4GB), windows, though, only sees about 3.3GB

In theory a 64 bit operating system can address 2^64 = 18,446,744,073,709,551,616 (4 Exobytes)
DE AA EB
Thorium
Addict
Addict
Posts: 1305
Joined: Sat Aug 15, 2009 6:59 pm

Re: Memory Limit

Post by Thorium »

davido wrote:In theory a 32 bit operating system can only address 2^32 = 4,294,967,296 (4GB), windows, though, only sees about 3.3GB

In theory a 64 bit operating system can address 2^64 = 18,446,744,073,709,551,616 (4 Exobytes)
Not realy true.
Windows does see 4GB. However your hardware is mapped to the memory so it depends on the mainboard and other hardware, not on the OS how much of the 4GB are available. Besides that the CPU actualy can address more, just not in a linear mode. You can use API do swap memory regions to use more than 4GB, however it's complicated to program.

The solution is using a 64bit system, which can not address 4 exobytes but only 72 terabytes. The address limit is not dictated by the nativ register size but by the width of the address line. Which allows only 72TB on modern x86 CPU's.

If you have more than 3GB of memory you should stop using a 32bit system.
User avatar
Lord
Addict
Addict
Posts: 900
Joined: Tue May 26, 2009 2:11 pm

Re: Memory Limit

Post by Lord »

charvista wrote:... So there are indeed limits, depending on the computer architecture, the version and subversion of Windows! Why not making it universal?! But ok, that's Bill Gates' choice.
...
That's not the whole truth.
As Fred stated here, there is also a 2GB limit by PureBasic itself.
At least in regard to canvas and images.
The reason is that PB uses CreateDIBSection for memory allocation.
Right now there is no way to use more than 2GB for each canvas or
image even if you have 64GB available.
Image
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Memory Limit

Post by davido »

Hi Thorium,

Thank you, nice to know the real truth! :D
DE AA EB
User avatar
NicknameFJ
User
User
Posts: 90
Joined: Tue Mar 17, 2009 6:36 pm
Location: Germany

Re: Memory Limit

Post by NicknameFJ »

Thorium wrote: Which allows only 72TB on modern x86 CPU's.
I think he meant on modern x64 CPU´s


NicknameFJ
PS: Sorry for my weird english, but english is not my native language.



Image
Post Reply