Bruce
Eitman

Windows CE Musings

Home  |
Contact  |
Syndication
|
Login

92 Posts | 0 Stories | 91
Comments | 0 Trackbacks

News

Bruce
Works at
Awards
and Acheivements
Windows Embedded CE 6.0 Developer

Tag Cloud

.NET
Compact Framework

BIB
File

blddemo

Build.exe

C

Catalog

CEbuild.bat

Clone

Dat
Files

Data
Abort

DEBUGMSG

DIRS
File

Driver

Drivers

Makeimg

Object
Store

PBXMLUtils

Platform
Builder

RETAILMSG

Sources

more
tags...

Archives

September,
2008 (7)

August, 2008
(16)

July, 2008
(17)

June, 2008
(29)

May, 2008
(23)

Post Categories

My Profile
(rss)

Serial Debug
Menu (rss)

Building
Windows CE (rss)

Windows CE
Kernel (rss)

Windows CE
Bootloader (rss)

When Things Go
Wrong (rss)

Windows CE
General (rss)

Windows CE
Drivers (rss)

Platorm
Builder Catalog (rss)

Platform
Builder General (rss)

.NET Compact
Framework (rss)

Books on my
Shelf (rss)

Windows
CE: Automatically setting the Object Store Size

A customer asked me an interesting question
today. He wanted to know how to know how much space his system needed for
the Object Store. That had me thinking that there could be a way to monitor
the size and automatically adjust it, Windows Mobile does that. Of course
Windows Mobile probably has a better way to manage the Object Store size than
this, I am guessing that it monitors the size within FileSys and adjusts it as
requests come in.

I wrote the following code just to see what
could be done. I don’t necessary think that this is a good way to do it,
but it is something that could be used to monitor the Object Store.

CheckObjectStoreSize() will check the current
number of pages being used by the Object Store and will adjust the size to the
maximum of:

-
The documented minimum size of 128K

o   #define
DOCUMENTED_MIN_OS_PAGES( PageSize ) (( 128 * 1024 )/PageSize )

-
Current number of pages being used plus MIN_FREE_PAGES, which is a
random number that I picked

o   #define
MIN_FREE_PAGES( PageSize )
((100 * 1024)/PageSize)

Because the number of pages being used is
obtained using GetSStoreInformation() this function will both increase and
decrease the size of the Object Store.

void
CheckObjectStoreSize()

{

DWORD StorePages,

DWORD RamPages

DWORD PageSize;

DWORD CurrentNeededSize;

DWORD Status;

DWORD ObjectStorePages;

STORE_INFORMATION StoreInfo;

GetSystemMemoryDivision(&StorePages, &RamPages, &PageSize);

GetStoreInformation(&StoreInfo);

CurrentNeededSize = ((StoreInfo.dwStoreSize - StoreInfo.dwFreeSize)/PageSize) +
1 ;

ObjectStorePages = DOCUMENTED_MIN_OS_PAGES(PageSize);

// Check to see if the current Object Store needs to be bigger

if( ObjectStorePages < (CurrentNeededSize + MIN_FREE_PAGES( PageSize)
))

{

ObjectStorePages = (CurrentNeededSize + MIN_FREE_PAGES( PageSize));

}

// Do we have enough free space to increase the Object
Store?

if (ObjectStorePages >= (StorePages + RamPages))

{

RETAILMSG(1,(TEXT("Out of memory to increase Object Store\n")));

return;

}

Status = SetSystemMemoryDivision (ObjectStorePages);

if (Status)

{

RETAILMSG(1,(TEXT("Failed to set Object Store: ")));

switch(Status)

{

case SYSMEM_MUSTREBOOT:

RETAILMSG(1,(TEXT(" SYSMEM_MUSTREBOOT\n")));

break;

case SYSMEM_REBOOTPENDING:

RETAILMSG(1,(TEXT(" SYSMEM_REBOOTPENDING\n")));

break;

case SYSMEM_FAILED:

RETAILMSG(1,(TEXT(" SYSMEM_FAILED (%d)\n", GetLastError())));

break;

default:

break;

}

}

}

I then tested the CheckObjectStoreSize() by
calling it in a loop from WinMain(). The loop copies a file from the
storage card to the Object Store 50 times followed by deleting the files on the
next 40 times through the loop.

int
WINAPI WinMain(

HINSTANCE hInstance,

HINSTANCE hPrevInstance,

LPTSTR    lpCmdLine,

int       nCmdShow

)

{

DWORD Counter = 0;

TCHAR FileName[ MAX_PATH ];

BOOL Toggle = FALSE;

while( 1 )

{

Sleep( 5000 );

wsprintf( FileName, TEXT("\\File%d.txt"), Counter++ );

RETAILMSG( 1, (TEXT("Copy to %s\n"), FileName ));

if( Counter > 50 )

{

Toggle = !Toggle;

Counter = 0;

}

if( Toggle )

{

if( !DeleteFile( FileName ))

RETAILMSG( 1, (TEXT("File Delete failed %d\n"), GetLastError() ));

}

else

{

if( !CopyFile( TEXT("\\Storage Card\\a.txt"), FileName, FALSE ))

RETAILMSG( 1, (TEXT("File Copy failed %d\n"), GetLastError() ));

}

CheckObjectStoreSize();

}

}

Tags: ObjectStore

Copyright © 2008 – Bruce Eitman

All Rights Reserved

posted on Wednesday, August 20, 2008 9:40 PM

Feedback
No comments posted yet.

Post Feedback

Title:

Please enter a title

Name:

Please enter your name

Email: (never displayed)

Please enter your email

Url:

Comments:
Please enter a comment

Please enter the answer to the supplied
question.Please add
8 and 8 and type the answer here:

Enter the
code shown above:Please enter
the correct word

Remember Me?

Powered by:

Skin design by Mark Wagner, Adapted by
David Vidmar

Copyright © Bruce
Eitman