How to allocate program memory and storage before running my application in Wince?

Asked

Viewed 830 times

6

I am reprogramming a C# application to run on Windows CE, but my machine has little memory.
Therefore, I need to allocate the appropriate amount of processing memory (program memory) and storage memory (Storage memory). I can’t manually allocate this to each reboot, so I found the function Setsystemmemorydivision().
The code to allocate memory is basically the following:

        //Confere se a memória está alocada corretamente
        while (storage_page != 800)
        {
            //Seta a memória para 800 pages de 4096 bytes cada (4Kb * 800 = 3.200Kb)
            storage_page = 800;

            //Grava a memória setada
            SetSystemMemoryDivision(storage_page);

            Thread.Sleep(200);

            //Lê a memória do sistema
            GetSystemMemoryDivision(ref storage_page, ref ram_page, ref page_size);
        }
        chamamenu();

The function is working in debug mode, but whenever I restart the machine and try to run the program, the system crashes.

How can I ensure that the memory has been allocated before running any other process that might lock the machine? It is possible that the application is allocating more than the 32mb available for RAM.

  • In the MSDN says that this function was "deprecated" and should not be used.

  • 1

    Thank you, dcastro. Unfortunately all Windows CE is obsolete, but it is still the default environment for this application. Some function has replaced the old one or Microsoft simply thinks that we no longer need to manage the memories?

2 answers

2


Problem solved.

The main problem was with the GC of CF 2.0, which was not managing the collection correctly.
With an update from . NET CF v2.0 for v3.5 both on machine and project, GC started to properly manage the collection and the application worked perfectly.

Thank you to everyone who tried to help and hope that I helped someone with similar problems.

0

  • Unfortunately I can not use the first option, because Wince 5.0 still uses the . NET CF 2.0. But the second option seemed to me quite interesting. The biggest problem to implement it is that I do not know the size of the allocation (Mapsize) that I have to do, since memory consumption occurs by creating instances of forms.

  • If possible, use Structs and the Marshal class to pick up the sizes.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.