Author Topic: Test of /LARGEADDRESSAWARE linker option  (Read 4639 times)

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 7544
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Test of /LARGEADDRESSAWARE linker option
« 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.

Code: [Select]
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    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.

Code: [Select]
@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:
« Last Edit: March 03, 2016, 07:44:50 PM by hutch-- »
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

mabdelouahab

  • Member
  • ***
  • Posts: 454
Re: Test of /LARGEADDRESSAWARE linker option
« Reply #1 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?

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 7544
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Test of /LARGEADDRESSAWARE linker option
« Reply #2 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:
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

jj2007

  • Member
  • *****
  • Posts: 10548
  • Assembler is fun ;-)
    • MasmBasic
Re: Test of /LARGEADDRESSAWARE linker option
« Reply #3 on: March 03, 2016, 08:24:21 PM »
Code: [Select]
    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:
Code: [Select]
00650020 Allocation 1 - 1gig
7FFF0020 Allocation 2 - 1gig
C0000020 Allocation 3 - 960 mb

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 7544
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Test of /LARGEADDRESSAWARE linker option
« Reply #4 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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

TWell

  • Member
  • ****
  • Posts: 748
Re: Test of /LARGEADDRESSAWARE linker option
« Reply #5 on: March 03, 2016, 11:21:52 PM »
Windows 10 Home x64
Code: [Select]
.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
Code: [Select]
01E38020h
7FFF4020h
C0001020h

jj2007

  • Member
  • *****
  • Posts: 10548
  • Assembler is fun ;-)
    • MasmBasic
Re: Test of /LARGEADDRESSAWARE linker option
« Reply #6 on: March 04, 2016, 02:16:41 AM »
mov pMem3, alloc(1024*1024*1023+720000)

Code: [Select]
005C0020 Allocation 1 - 1gig
7FFF0020 Allocation 2 - 1gig
C0000020 Allocation 3 - 1023.6866 mb

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 7544
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Test of /LARGEADDRESSAWARE linker option
« Reply #7 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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

jj2007

  • Member
  • *****
  • Posts: 10548
  • Assembler is fun ;-)
    • MasmBasic
Re: Test of /LARGEADDRESSAWARE linker option
« Reply #8 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

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 7544
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Test of /LARGEADDRESSAWARE linker option
« Reply #9 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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy: