News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Test of /LARGEADDRESSAWARE linker option

Started by hutch--, March 03, 2016, 02:23:22 PM

Previous topic - Next topic

hutch--

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:

mabdelouahab

it works well (Win8.1 x64), I was looking for this  :t
Allocation 1 - 1tb: What is meant by 1tb ,is she 1gb?

hutch--

 :biggrin:

Sorry about that, I have been configuring big disks lately and typed the wrong size in. Its definitely 1GB.  :redface:

jj2007

    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

hutch--

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.

TWell

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

jj2007

mov pMem3, alloc(1024*1024*1023+720000)

005C0020 Allocation 1 - 1gig
7FFF0020 Allocation 2 - 1gig
C0000020 Allocation 3 - 1023.6866 mb

hutch--

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.

jj2007

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--

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.