News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Process Heap Memory Status

Started by dedndave, November 10, 2013, 11:31:59 AM

Previous topic - Next topic

dedndave

a few years ago, Hutch wrote this handy little routine to show memory status

http://www.masmforum.com/board/index.php?topic=12157

i modified it a bit to see how it interacts with a large heap allocation
i call Hutch's code
allocate as much as i can in the process heap
call Hutch's code again
free the allocated block
call Hutch's code a final time.....
66%  memory free

2039 megabytes installed physical memory
1334 megabytes available physical memory

3410 megabytes maximum page file size
2889 megabytes available page file

2048 megabytes total virtual memory
2042 megabytes available virtual memory

777FF000 Bytes Allocated

66%  memory free

2039 megabytes installed physical memory
1334 megabytes available physical memory

3410 megabytes maximum page file size
973 megabytes available page file

2048 megabytes total virtual memory
130 megabytes available virtual memory

777FF000 Bytes Freed

66%  memory free

2039 megabytes installed physical memory
1334 megabytes available physical memory

3410 megabytes maximum page file size
2889 megabytes available page file

2048 megabytes total virtual memory
2042 megabytes available virtual memory


is there a good way to know how much is really available in the process heap ?   :redface:

TouEnMasm


http://msdn.microsoft.com/en-us/library/ms810603.aspx

you can directly inform the linker by using the /HEAP linker switch

The PE file format is the good way
IMAGE_OPTIONAL_HEADER32
.....
   SizeOfHeapReserve DWORD ?
   SizeOfHeapCommit DWORD ?
...


Fa is a musical note to play with CL

dedndave

yah - the default is 0x10000 (64K) bytes reserved address space and 0x1000 (4K) bytes committed memory
i don't really want to change that

the information is there, you just have to "parse" your way through it
Hutch's routine uses GlobalMemoryStatusEx   :P
i wrote a little loop using VirtualQuery
BaseAddr AlocBase AlocProt RgnSize  State    Protect  Type

00400000 00400000 00000080 00001000 00001000 00000002 01000000
00401000 00400000 00000080 00001000 00001000 00000020 01000000
00402000 00400000 00000080 00001000 00001000 00000002 01000000
00403000 00400000 00000080 00001000 00001000 00000004 01000000
00404000 00000000 00000000 7780C000 00010000 00000001 00000000
77C10000 77C10000 00000080 00001000 00001000 00000002 01000000
77C11000 77C10000 00000080 0004C000 00001000 00000020 01000000
77C5D000 77C10000 00000080 00002000 00001000 00000008 01000000
77C5F000 77C10000 00000080 00001000 00001000 00000004 01000000
77C60000 77C10000 00000080 00001000 00001000 00000008 01000000
77C61000 77C10000 00000080 00003000 00001000 00000004 01000000
77C64000 77C10000 00000080 00004000 00001000 00000002 01000000
77C68000 00000000 00000000 04B98000 00010000 00000001 00000000
7C800000 7C800000 00000080 00001000 00001000 00000002 01000000
7C801000 7C800000 00000080 00084000 00001000 00000020 01000000
7C885000 7C800000 00000080 00003000 00001000 00000004 01000000
7C888000 7C800000 00000080 00002000 00001000 00000008 01000000
7C88A000 7C800000 00000080 0006C000 00001000 00000002 01000000
7C8F6000 00000000 00000000 0000A000 00010000 00000001 00000000
7C900000 7C900000 00000080 00001000 00001000 00000002 01000000
7C901000 7C900000 00000080 0007D000 00001000 00000020 01000000
7C97E000 7C900000 00000080 00003000 00001000 00000004 01000000
7C981000 7C900000 00000080 00002000 00001000 00000008 01000000
7C983000 7C900000 00000080 0002F000 00001000 00000002 01000000
7C9B2000 00000000 00000000 02D3E000 00010000 00000001 00000000
7F6F0000 7F6F0000 00000020 00007000 00001000 00000020 00040000
7F6F7000 7F6F0000 00000020 000F9000 00002000 00000000 00040000
7F7F0000 00000000 00000000 007C0000 00010000 00000001 00000000
7FFB0000 7FFB0000 00000002 00024000 00001000 00000002 00040000
7FFD4000 00000000 00000000 00009000 00010000 00000001 00000000
7FFDD000 7FFDD000 00000004 00001000 00001000 00000004 00020000
7FFDE000 7FFDE000 00000004 00001000 00001000 00000004 00020000
7FFDF000 00000000 00000000 00001000 00010000 00000001 00000000
7FFE0000 7FFE0000 00000002 00001000 00001000 00000002 00020000
7FFE1000 7FFE0000 00000002 0000F000 00002000 00000001 00020000

777FF000 Bytes Allocated At 00410020

BaseAddr AlocBase AlocProt RgnSize  State    Protect  Type

00400000 00400000 00000080 00001000 00001000 00000002 01000000
00401000 00400000 00000080 00001000 00001000 00000020 01000000
00402000 00400000 00000080 00001000 00001000 00000002 01000000
00403000 00400000 00000080 00001000 00001000 00000004 01000000
00404000 00000000 00000000 0000C000 00010000 00000001 00000000
00410000 00410000 00000004 77800000 00001000 00000004 00020000
77C10000 77C10000 00000080 00001000 00001000 00000002 01000000
77C11000 77C10000 00000080 0004C000 00001000 00000020 01000000
77C5D000 77C10000 00000080 00002000 00001000 00000008 01000000
77C5F000 77C10000 00000080 00001000 00001000 00000004 01000000
77C60000 77C10000 00000080 00001000 00001000 00000008 01000000
77C61000 77C10000 00000080 00003000 00001000 00000004 01000000
77C64000 77C10000 00000080 00004000 00001000 00000002 01000000
77C68000 00000000 00000000 04B98000 00010000 00000001 00000000
7C800000 7C800000 00000080 00001000 00001000 00000002 01000000
7C801000 7C800000 00000080 00084000 00001000 00000020 01000000
7C885000 7C800000 00000080 00003000 00001000 00000004 01000000
7C888000 7C800000 00000080 00002000 00001000 00000008 01000000
7C88A000 7C800000 00000080 0006C000 00001000 00000002 01000000
7C8F6000 00000000 00000000 0000A000 00010000 00000001 00000000
7C900000 7C900000 00000080 00001000 00001000 00000002 01000000
7C901000 7C900000 00000080 0007D000 00001000 00000020 01000000
7C97E000 7C900000 00000080 00003000 00001000 00000004 01000000
7C981000 7C900000 00000080 00002000 00001000 00000008 01000000
7C983000 7C900000 00000080 0002F000 00001000 00000002 01000000
7C9B2000 00000000 00000000 02D3E000 00010000 00000001 00000000
7F6F0000 7F6F0000 00000020 00007000 00001000 00000020 00040000
7F6F7000 7F6F0000 00000020 000F9000 00002000 00000000 00040000
7F7F0000 00000000 00000000 007C0000 00010000 00000001 00000000
7FFB0000 7FFB0000 00000002 00024000 00001000 00000002 00040000
7FFD4000 00000000 00000000 00009000 00010000 00000001 00000000
7FFDD000 7FFDD000 00000004 00001000 00001000 00000004 00020000
7FFDE000 7FFDE000 00000004 00001000 00001000 00000004 00020000
7FFDF000 00000000 00000000 00001000 00010000 00000001 00000000
7FFE0000 7FFE0000 00000002 00001000 00001000 00000002 00020000
7FFE1000 7FFE0000 00000002 0000F000 00002000 00000001 00020000

777FF000 Bytes Freed

BaseAddr AlocBase AlocProt RgnSize  State    Protect  Type

00400000 00400000 00000080 00001000 00001000 00000002 01000000
00401000 00400000 00000080 00001000 00001000 00000020 01000000
00402000 00400000 00000080 00001000 00001000 00000002 01000000
00403000 00400000 00000080 00001000 00001000 00000004 01000000
00404000 00000000 00000000 7780C000 00010000 00000001 00000000
77C10000 77C10000 00000080 00001000 00001000 00000002 01000000
77C11000 77C10000 00000080 0004C000 00001000 00000020 01000000
77C5D000 77C10000 00000080 00002000 00001000 00000008 01000000
77C5F000 77C10000 00000080 00001000 00001000 00000004 01000000
77C60000 77C10000 00000080 00001000 00001000 00000008 01000000
77C61000 77C10000 00000080 00003000 00001000 00000004 01000000
77C64000 77C10000 00000080 00004000 00001000 00000002 01000000
77C68000 00000000 00000000 04B98000 00010000 00000001 00000000
7C800000 7C800000 00000080 00001000 00001000 00000002 01000000
7C801000 7C800000 00000080 00084000 00001000 00000020 01000000
7C885000 7C800000 00000080 00003000 00001000 00000004 01000000
7C888000 7C800000 00000080 00002000 00001000 00000008 01000000
7C88A000 7C800000 00000080 0006C000 00001000 00000002 01000000
7C8F6000 00000000 00000000 0000A000 00010000 00000001 00000000
7C900000 7C900000 00000080 00001000 00001000 00000002 01000000
7C901000 7C900000 00000080 0007D000 00001000 00000020 01000000
7C97E000 7C900000 00000080 00003000 00001000 00000004 01000000
7C981000 7C900000 00000080 00002000 00001000 00000008 01000000
7C983000 7C900000 00000080 0002F000 00001000 00000002 01000000
7C9B2000 00000000 00000000 02D3E000 00010000 00000001 00000000
7F6F0000 7F6F0000 00000020 00007000 00001000 00000020 00040000
7F6F7000 7F6F0000 00000020 000F9000 00002000 00000000 00040000
7F7F0000 00000000 00000000 007C0000 00010000 00000001 00000000
7FFB0000 7FFB0000 00000002 00024000 00001000 00000002 00040000
7FFD4000 00000000 00000000 00009000 00010000 00000001 00000000
7FFDD000 7FFDD000 00000004 00001000 00001000 00000004 00020000
7FFDE000 7FFDE000 00000004 00001000 00001000 00000004 00020000
7FFDF000 00000000 00000000 00001000 00010000 00000001 00000000
7FFE0000 7FFE0000 00000002 00001000 00001000 00000002 00020000
7FFE1000 7FFE0000 00000002 0000F000 00002000 00000001 00020000

the key areas:
BaseAddr AlocBase AlocProt RgnSize  State    Protect  Type

00404000 00000000 00000000 7780C000 00010000 00000001 00000000
777FF000 Bytes Allocated At 00410020
00404000 00000000 00000000 0000C000 00010000 00000001 00000000
00410000 00410000 00000004 77800000 00001000 00000004 00020000
777FF000 Bytes Freed
00404000 00000000 00000000 7780C000 00010000 00000001 00000000


it looks like the State member can help do the job

MEM_COMMIT EQU 1000h
MEM_FREE   EQU 10000h