Bug 34382 - Marshal.AllocHGlobal out of memory exception with 64-bit ptr
Summary: Marshal.AllocHGlobal out of memory exception with 64-bit ptr
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: Interop (show other bugs)
Version: 4.0.0
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-09-29 05:27 UTC by Paolo
Modified: 2015-10-06 13:41 UTC (History)
3 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description Paolo 2015-09-29 05:27:07 UTC
I am trying to allocate unmanaged memory using Marshal.AllocHGlobal

When the size is greater than int.MaxValue (~2GB) I get this error message:
[ERROR] FATAL UNHANDLED EXCEPTION: System.OutOfMemoryException: Out of memory
 at (wrapper managed-to-native) System.Runtime.InteropServices.Marshal:AllocHGlobal (intptr)

This error occurs with mono Stable 4.0.4 and Alpha 4.2.1 on Ubuntu Server 14.04 in a virtual machine. Both the mono versions are using the 64-bit architecture. The code is compiled with VS2013 on a windows server 2012R2 machine and I made sure that the code was compiled in 64-bit checking that IntPtr.Size == 8.
Comment 1 Zoltan Varga 2015-10-06 11:09:13 UTC
On unix, AllocHGlobal uses the same allocator as malloc() does, and it looks like that can't allocate more than a certain amount of memory.
Comment 2 Paolo 2015-10-06 13:21:15 UTC
I did this test: on the same machine I used malloc() to allocate 30GB and it worked. I compiled the code using gcc.
Is it possible that AllocHGlobal uses a 32-bit version of malloc()?
Comment 3 Zoltan Varga 2015-10-06 13:41:54 UTC
Fixed by mono master 60cab7008ba24d189054d52bd39c8c9ee411e9db.

Note You need to log in before you can comment on or make changes to this bug.