The MASM Forum

General => The Laboratory => Topic started by: hutch-- on March 03, 2016, 02:23:22 PM

Title: Test of /LARGEADDRESSAWARE linker option
Post by: hutch-- on March 03, 2016, 02:23:22 PM
This is only for a Win64 machine, Win7 upwards with enough memory available. It won't work on XP and especially on a machine with limited memory. You can get about 2.75 gig on most later hardware.


; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    include \masm32\include\masm32rt.inc
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    .data?
      pMem1 dd ?
      pMem2 dd ?
      pMem3 dd ?

    .code

start:
   
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    call main

    exit

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

main proc

    mov pMem1, alloc(1024*1024*1024)
    fn MessageBox,0,hex$(pMem1),"Allocation 1 - 1gig",MB_OK

    mov pMem2, alloc(1024*1024*1024)
    fn MessageBox,0,hex$(pMem2),"Allocation 2 - 1gig",MB_OK

    mov pMem3, alloc(1024*1024*768)
    fn MessageBox,0,hex$(pMem3),"Allocation 3 - 768 mb",MB_OK

    free pMem3
    free pMem2
    free pMem1

    ret

main endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

end start


Here is the batch file to build it.


@echo off

if not exist rsrc.rc goto over1
\masm32\bin\rc /v rsrc.rc
\masm32\bin\cvtres /machine:ix86 rsrc.res
:over1

if exist "mtest.obj" del "mtest.obj"
if exist "mtest.exe" del "mtest.exe"

\masm32\bin\ml /c /coff "mtest.asm"
if errorlevel 1 goto errasm

:nores
\masm32\bin\Link /SUBSYSTEM:WINDOWS /LARGEADDRESSAWARE /OPT:NOREF "mtest.obj"
if errorlevel 1 goto errlink
dir "mtest.*"
goto TheEnd

:errlink
echo _
echo Link error
goto TheEnd

:errasm
echo _
echo Assembly Error
goto TheEnd

:TheEnd

pause


You will need to save the posted code as mtest.asm to build it.

LATER : Modified to fix a labeling error.  :biggrin:
Title: Re: Test of /LARGEADDRESSAWARE linker option
Post by: mabdelouahab on March 03, 2016, 05:32:02 PM
it works well (Win8.1 x64), I was looking for this  :t
Allocation 1 - 1tb: What is meant by 1tb ,is she 1gb?
Title: Re: Test of /LARGEADDRESSAWARE linker option
Post by: hutch-- on March 03, 2016, 07:42:40 PM
 :biggrin:

Sorry about that, I have been configuring big disks lately and typed the wrong size in. Its definitely 1GB.  :redface:
Title: Re: Test of /LARGEADDRESSAWARE linker option
Post by: jj2007 on March 03, 2016, 08:24:21 PM
    mov pMem1, alloc(1024*1024*1024)
    print hex$(pMem1), " Allocation 1 - 1gig", 13, 10

    mov pMem2, alloc(1024*1024*1024)
    print hex$(pMem2), " Allocation 2 - 1gig", 13, 10

    mov pMem3, alloc(1024*1024*960)
    print hex$(pMem3), " Allocation 3 - 960 mb", 13, 10


Win7-64:
00650020 Allocation 1 - 1gig
7FFF0020 Allocation 2 - 1gig
C0000020 Allocation 3 - 960 mb
Title: Re: Test of /LARGEADDRESSAWARE linker option
Post by: hutch-- on March 03, 2016, 09:14:33 PM
Aha, means you have a bit more win32 address space than I have. I know you can run multiple applications on a machine with a lot of memory but I have not yet seen a fast way to cross use that memory. You can try memory mapped files and conventional private messaging between consenting apps but I have my doubts that it is fast enough.
Title: Re: Test of /LARGEADDRESSAWARE linker option
Post by: TWell on March 03, 2016, 11:21:52 PM
Windows 10 Home x64
.386
.model flat,stdcall

ExitProcess PROTO :DWORD
GlobalAlloc PROTO :DWORD,:DWORD
GlobalFree PROTO :DWORD
includelib kernel32.lib

MessageBoxA PROTO :DWORD,:DWORD,:DWORD,:DWORD
includelib user32.lib

printf PROTO C :DWORD,:VARARG
includelib msvcrt.lib

.data
sfmt db "%ph",10,0

.data?
pMem1 dd ?
pMem2 dd ?
pMem3 dd ?

.code
main proc
invoke GlobalAlloc,40h,1024*1024*1024 ; 1. Gb
mov pMem1, eax
invoke printf, addr sfmt, eax
invoke GlobalAlloc,40h,1024*1024*1024 ; 2. Gb
mov pMem2, eax
invoke printf, addr sfmt, eax
invoke GlobalAlloc,40h,1024*1024*1022 ; 3. Gb
mov pMem3, eax
invoke printf, addr sfmt, eax
invoke MessageBoxA,0,0,0,0
invoke GlobalFree,pMem1
invoke GlobalFree,pMem2
invoke GlobalFree,pMem3
invoke ExitProcess,0
main endp
end main
01E38020h
7FFF4020h
C0001020h
Title: Re: Test of /LARGEADDRESSAWARE linker option
Post by: jj2007 on March 04, 2016, 02:16:41 AM
mov pMem3, alloc(1024*1024*1023+720000)

005C0020 Allocation 1 - 1gig
7FFF0020 Allocation 2 - 1gig
C0000020 Allocation 3 - 1023.6866 mb
Title: Re: Test of /LARGEADDRESSAWARE linker option
Post by: hutch-- on March 04, 2016, 02:26:28 AM
JJ,

The difference is related to how much win32 address space is used by the OS and the video card, I used to get about 2850mb on my Win7 box when allocating memory, I get a bit less on this new box as it has a different video card.
Title: Re: Test of /LARGEADDRESSAWARE linker option
Post by: jj2007 on March 04, 2016, 04:18:51 AM
Hutch,

Sure there are little differences in memory usage. I find it amazing that so much is available from the theoretical limit of 3GB.

The more interesting question here is how our libraries behave when they are confronted with negative pointers. A quick and hopefully completely irrelevant search in \Masm32\m32lib\*.asm finds 35 files that contain jg and 51 that contain jl, plus 2 with js. Similar results for MasmBasic :P
Title: Re: Test of /LARGEADDRESSAWARE linker option
Post by: hutch-- on March 04, 2016, 04:48:15 AM
I think you are still safe there as you cannot allocate over 2 gig as a single block, you can certainly tile one block after another but you would have to write specific code to do it.
Title: Re: Test of /LARGEADDRESSAWARE linker option
Post by: npnw on March 23, 2016, 03:01:14 AM
Large memory support 4 gb tuning
https://msdn.microsoft.com/en-us/library/windows/desktop/bb613473(v=vs.85).aspx (https://msdn.microsoft.com/en-us/library/windows/desktop/bb613473(v=vs.85).aspx)
comparing memory allocation functions
https://msdn.microsoft.com/en-us/library/windows/desktop/aa366533(v=vs.85).aspx (https://msdn.microsoft.com/en-us/library/windows/desktop/aa366533(v=vs.85).aspx)
Heap Function
https://msdn.microsoft.com/en-us/library/windows/desktop/aa366711(v=vs.85).aspx (https://msdn.microsoft.com/en-us/library/windows/desktop/aa366711(v=vs.85).aspx)
global alloc function
https://msdn.microsoft.com/en-us/library/windows/desktop/aa366574(v=vs.85).aspx (https://msdn.microsoft.com/en-us/library/windows/desktop/aa366574(v=vs.85).aspx)

Hi Hutch! Hope this helps.

npnw