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

Re: 32Mb is not enough memory for App by Chris

Chris
Wed Nov 23 09:24:17 CST 2005

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


"Jon Brunson" <JonBrunson@NOSPAMinnovationsoftwareDOTcoPERIODuk> wrote in
message news:uKtRLHD8FHA.1484@tk2msftngp13.phx.gbl...
> 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



Re: 32Mb is not enough memory for App by Jon

Jon
Wed Nov 23 09:48:23 CST 2005

Chris Tacke, eMVP wrote:
> 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)?

Re: 32Mb is not enough memory for App by Chris

Chris
Wed Nov 23 09:56:56 CST 2005

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


"Jon Brunson" <JonBrunson@NOSPAMinnovationsoftwareDOTcoPERIODuk> wrote in
message news:OfZlbVE8FHA.2176@TK2MSFTNGP14.phx.gbl...
> Chris Tacke, eMVP wrote:
>> 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)?



Re: 32Mb is not enough memory for App by Jon

Jon
Wed Nov 23 11:06:45 CST 2005

Chris Tacke, eMVP wrote:
> The OS limits the process space to 32MB, there's no way around that.
>

Thanks Chris, at least I know which tree to bark up now :o)