views:

893

answers:

5

When moving my .Net Compact Framework application to the SD-card of a Windows CE device, the program executes slower then running it from the internal memory.

I thought, the start-up might be slower, but it is the whole program. There is no IO to the storage card.

Why is my application so slow and how does the compact framework handles and loads the assemblies?

A: 

The SD-Card memory is an order of magnitude (or more) slower than RAM. I believe most device manufacturers recommend against running from non-volatile storage. (The Symbol MC1000 definitely)

Mitch Wheat
I'm working on a Symbol MC 3000. Now we are testing Kingston 133x http://www.kingston.com/flash/sdultimate.asp, but as you said, they are magnitudes slower then the internal memory.
Louis Haußknecht
Internal flash may or may not be executable. The read-access time difference between NAND and NOR flash is also gigantic, so if one is NAND and one is NOR, I would expect a large difference.
ctacke
As Louis points out though - wouldn't you expect the startup to be slow (as the program is loaded from the SD card into RAM), but then the application to be faster afterwards since all the program code is already in memory?
John Sibly
@John Sibly: not if there are resources like images on the card being pulled
ctacke
@Chris: We don't have resources, that are pulled. The only thing we call is a Symbol managed dll for the scan-engine, which in turn does p/invoke to the native dlls. Maybe our app is getting too large for the device?!
Louis Haußknecht
+10  A: 

It has to do with demand-paging. Your app cannot be run directly from the SD-card, as SD is not executable media so it has to be pulled into RAM to run. Windows CE doesn't typically have a whole lot of RAM, so the loader doesn't pull your entire application into RAM to run. Sure, your heaps and stacks will be in RAM, but the actual IL code in the assembly itself is paged in as needed. It's also paged out when the system decides it no longer needs a specific page.

This paging can have an impact on performance, though I'm a bit surprised that it's a large impact unless the app itself is really large (like if you have lots of embedded resources that it's pulling out of the assembly).

ctacke
Okay. We want to use the sd-card, so that we can deploy additional resources and dlls (maybe also the pdb-files) to the device. At the moment this is not possible because of the size constraints of the internal memory. As you said, does it make sense to put everything on the sd-card?
Louis Haußknecht
IIRC, "main memory" of a CE device cannot execute in-place either, so the application code would still need to be loaded into ram.
crashmstr
@crashmstr: depends on the device, but in most cases it is executable, whether is RAM or flash mounted as XIP.
ctacke
@Louis: You don't have a lot of choice - if the resources are too large to fit on the device, you have to use storage. The only thing you can do to mitigate the effect is to test and find the fastest read-speed card you can.
ctacke
+1  A: 

I agree with the previous "demand-paging" answer by ctacke.

A solution you might try is to execute a loader program from the SD-card that copies your actual executable and DLLs from card to hard disk, and then execute your program from the loader. In subsequent executions the loader can detect if the hard disk version is up to date, and if so just launch it directly. If the hard disk version is not up to date, the loader will again copy out-of-date files from card and then execute the actual program.

I have done this before from a program loaded at a remote network location, and it worked very well.

Jason Jackson
A: 

Some device will crash your program if application is on sd-card. It happens while suspend-power-on device.

Malx
Yes, and I explained *why* a month ago.
ctacke
On our Symbol/Motorola Devices we avoided this by setting this reg key [HKEY_LOCAL_MACHINE\Drivers\BuiltIn\sdmmcloader]"NoRemoveOnResume"=dword:00000001
Louis Haußknecht
A: 

Louis Haußknecht, Many Thanks for you. I have been solved the 0xc0000005 exception which program run on SD Card by setting registy that you suggest. ^^

sang_sorn