32Mb is not enough memory for App

J

Jon Brunson

Hi all,

From what I've read each CE app can only use 32Mb of memory, is there
anyway to expand this?

Our App is rather large and demanding, and sometimes the app runs out of
memory, usually while doing Sql-stuff.

I've looked into VirtualAlloc, but firstly I don't /really/ understand
it, and secondly, it seems to makes no difference in our App.

Below is an app I whipped up to test memory usage. On my device it runs
39 times, then throws an out of memory exception both with, and without
the VirtualAlloc code commented-out.

[VB.NET]
Public Class Form1
Inherits System.Windows.Forms.Form

Public Shared Sub Main()
Application.Run(New Form1)
End Sub

<System.Runtime.InteropServices.DllImport("coredll")> _
Private Function VirtualAlloc(ByVal lpStartAddr As IntPtr, ByVal size
As Integer, ByVal flAllocationType As Integer, ByVal flProtect As
Integer) As IntPtr
End Function

<System.Runtime.InteropServices.DllImport("coredll")> _
Private Function GetLastError() As Integer
End Function

Private MEM_RESERVE As Integer = &H2000
Private MEM_COMMIT As Integer = &H1000
Private PAGE_READWRITE As Integer = &H4
Private PAGE_NOACCESS As Integer = &H1

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.Visible = True
Application.DoEvents()
Dim offset As Integer = 1

'Dim x As IntPtr = Me.VirtualAlloc(Nothing, 2 * 1024 * 1024,
MEM_COMMIT Or MEM_RESERVE, PAGE_READWRITE)
'If x.ToString() = "0" Then
' MessageBox.Show(Me.GetLastError().ToString())
'End If

Try
While True
Dim p As New PictureBox
p.Bounds = New Rectangle(offset * 8, offset * 8, 25, 25)
p.Image = New Bitmap(500, 700)
Me.Text = offset
offset += 1
Application.DoEvents()
End While
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try

End Sub
End Class
[/VB.NET]

Thanks for reading, and I hope someone is able to help/advise me
 
C

Chris Tacke, eMVP

VirtualAlloc isn't going to do anything for you. Yes, it allocates outside
the process space, but unless you're manually allocating and using memory
instead of using the .NET classes (which I seriously doubt), then it's of no
use. The classes you call would have to use it, and you have no control
over that.

In your "sample" you're not Disposing your GDI objects, so I'm not at all
surprised that you get an OOM exception. Follow the general rule that if
something publicly exposes Dispose(), then you should call it when you're
done with the resource. The VirtualAlloc being there does nothing.

--
Chris Tacke
Co-founder
OpenNETCF.org
Are you using the SDF? Let's do a case study.
Email us at d c s @ o p e n n e t c f . c o m
http://www.opennetcf.org/donate
 
J

Jon Brunson

VirtualAlloc isn't going to do anything for you. Yes, it allocates outside
the process space, but unless you're manually allocating and using memory
instead of using the .NET classes (which I seriously doubt), then it's of no
use. The classes you call would have to use it, and you have no control
over that.

In your "sample" you're not Disposing your GDI objects, so I'm not at all
surprised that you get an OOM exception. Follow the general rule that if
something publicly exposes Dispose(), then you should call it when you're
done with the resource. The VirtualAlloc being there does nothing.

The purpose of the example program was to cause an OoM Exception, to
test to see if the VirtualAlloc would give more itterations, which it
did not, and from what you've said it's obvious why now.

Is there any way to extend the amount of memory a process uses, or am I
stuck with 32Mb, and I'll have to stream-line my App (which wont be the
easiest thing in the world)?
 
C

Chris Tacke, eMVP

The OS limits the process space to 32MB, there's no way around that.

--
Chris Tacke
Co-founder
OpenNETCF.org
Are you using the SDF? Let's do a case study.
Email us at d c s @ o p e n n e t c f . c o m
http://www.opennetcf.org/donate
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top