开发者

Total and allocated heap on Windows Mobile when using Large Memory Area

开发者 https://www.devze.com 2022-12-19 17:02 出处:网络
I have a Windows Mobile 6.1 application which allocates memory not just from the 32MB process space but also from Large Memory Area - LMA (slot 60 and above).

I have a Windows Mobile 6.1 application which allocates memory not just from the 32MB process space but also from Large Memory Area - LMA (slot 60 and above).

MEMORYSTATUS structure gives me memory usage information of 32MB process slot only. Is there a way to compute total heap available from the system and allocated heap开发者_开发百科 by the application when LMA is being used?


Use VirtualQuery to walk every block in the LMA. If a block isn't marked MEM_FREE, then add its size to the total used.

For counting the memory used by a particular process I do something like this:

MEMORY_BASIC_INFORMATION mbi = { 0 };

/// total free memory available to the process
DWORD free = 0;

/// base memory address for the given process index (2-33). 
DWORD slot_base_addr = process_index * 0x02000000;

/// look at each memory region for the process. 
for( DWORD offset = 0x10000; 
    offset < 0x02000000; 
    offset += mbi.RegionSize )
{
    ::VirtualQuery( ( void* )( slot_base_addr + offset ), 
        &mbi, 
        sizeof( MEMORY_BASIC_INFORMATION ) );

    if( mbi.State == MEM_FREE )
    {
        free += ( mbi.RegionSize - ( ( ~( DWORD )mbi.BaseAddress + 1 ) & 0xffff ) ) & 0xffff0000;
    }
}

Just adapt the addresses in the for-loop to the LMA and it should work.

-PaulH

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号