473,557 Members | 2,776 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Maximum Size of Byte Array

Hi all,

I'm getting an OutOfMemoryExce ption when I initialize a byte array in
C# like this:

Byte[] test = new Byte[420000000];

I'm using ASP.NET 2.0. In ASP.Net 1.1 it works fine. So what am I doing
wrong?

What is the maximum length of a byte array?

Can somebody help me? Thanks in advance!

--
Gerrit Horeis

Software Developer
CI-Gate Development & Consulting GmbH
http://www.ci-gate.de
http://www.xira.de
http://www.bitbauer.de

Sep 26 '06 #1
23 16366
Gerrit <Ge***********@ web.dewrote:
I'm getting an OutOfMemoryExce ption when I initialize a byte array in
C# like this:

Byte[] test = new Byte[420000000];

I'm using ASP.NET 2.0. In ASP.Net 1.1 it works fine. So what am I doing
wrong?

What is the maximum length of a byte array?

Can somebody help me? Thanks in advance!
My guess is that ASP.NET 2.0 has some extra constraints in terms of how
much memory your app is allowed to use, to prevent wayward apps from
killing the machine. If I may say so, that's a fairly extreme use of
memory...

I can't say I know much about ASP.NET configuration - perhaps someone
in the ASP.NET group could help you there - but my gut feeling is
that's where the problem is.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 26 '06 #2
Thank you very much!

The strange on this behavior is that it sometimes occurs and sometimes
not.
But I'll try my luck in a ASP.NET group.

Thank you so far!

--
Gerrit Horeis

Software Developer
CI-Gate Development & Consulting GmbH
http://www.ci-gate.de
http://www.xira.de
http://www.bitbauer.de

Jon schrieb:
Gerrit <Ge***********@ web.dewrote:
I'm getting an OutOfMemoryExce ption when I initialize a byte array in
C# like this:

Byte[] test = new Byte[420000000];

I'm using ASP.NET 2.0. In ASP.Net 1.1 it works fine. So what am I doing
wrong?

What is the maximum length of a byte array?

Can somebody help me? Thanks in advance!

My guess is that ASP.NET 2.0 has some extra constraints in terms of how
much memory your app is allowed to use, to prevent wayward apps from
killing the machine. If I may say so, that's a fairly extreme use of
memory...

I can't say I know much about ASP.NET configuration - perhaps someone
in the ASP.NET group could help you there - but my gut feeling is
that's where the problem is.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 26 '06 #3
The strange on this behavior is that it sometimes occurs and sometimes not.
I guess it could also be some fragmentation of heaps / virtual address space.

=Get a 64-Bit system ;-) {but even 64-Bit .NET 2.0 has some 32-Bit limitations }

http://blogs.msdn.com/tess/archive/2...25/496898.aspx

http://msdn.microsoft.com/library/en...nitor_perf.asp
--
Thomas Scheidegger - MVP .NET - 'NETMaster'
http://www.cetus-links.org/oo_dotnet.html - http://dnetmaster.net/
Sep 26 '06 #4

"Gerrit" <Ge***********@ web.dewrote in message
news:11******** **************@ h48g2000cwc.goo glegroups.com.. .
| Hi all,
|
| I'm getting an OutOfMemoryExce ption when I initialize a byte array in
| C# like this:
|
| Byte[] test = new Byte[420000000];
|
| I'm using ASP.NET 2.0. In ASP.Net 1.1 it works fine. So what am I doing
| wrong?
|
| What is the maximum length of a byte array?
|
| Can somebody help me? Thanks in advance!
|
| --
| Gerrit Horeis
|
| Software Developer
| CI-Gate Development & Consulting GmbH
| http://www.ci-gate.de
| http://www.xira.de
| http://www.bitbauer.de
|

You should never assume that any portion of memory is available, even a
simple object allocation may fail. Now, as for your array of bytes,
theoretically the maximum size is ~2 billion bytes, but you will never be
able to allocate that size from a 32 bit process. Same goes for your 420
Mbytes array, allocating this from a 32 bit process will certainly lead to
OOM failures, as a result of heap fragmentation.
There is no guarantee that such an amount of contiguous memory space will be
available, certainly not when allocated in long running applications like
services (asp.net). For asp.net there is also a configuration parameter
which limits the total size of the process memory to a certain percentages
of the available virtual memory, while this is something to watch for, the
only solution to your problem, redesign your application in order to reduce
your memory consumption (this is a memory hog which doesn't scale at all),
or move to a 64 bit OS.

Willy.

Sep 26 '06 #5
Hi,
"Gerrit" <Ge***********@ web.dewrote in message
news:11******** **************@ h48g2000cwc.goo glegroups.com.. .
Hi all,

I'm getting an OutOfMemoryExce ption when I initialize a byte array in
C# like this:

Byte[] test = new Byte[420000000];

I'm using ASP.NET 2.0. In ASP.Net 1.1 it works fine. So what am I doing
wrong?

What is the maximum length of a byte array?

Why you need such a big array in the first place?

I bet it depends of either (or both) IIS and the framework

--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Sep 26 '06 #6

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us wrote
in message news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
| Hi,
|
|
| "Gerrit" <Ge***********@ web.dewrote in message
| news:11******** **************@ h48g2000cwc.goo glegroups.com.. .
| Hi all,
| >
| I'm getting an OutOfMemoryExce ption when I initialize a byte array in
| C# like this:
| >
| Byte[] test = new Byte[420000000];
| >
| I'm using ASP.NET 2.0. In ASP.Net 1.1 it works fine. So what am I doing
| wrong?
| >
| What is the maximum length of a byte array?
|
|
| Why you need such a big array in the first place?
|
| I bet it depends of either (or both) IIS and the framework
|
Hmm... IIS has nothing to do with this, ASP.NET runs in it's own process,
the framework only limit's the byte array size (just like any other object)
to ~2 GByte.
It's the way you allocate large contiguous blocks of memory from your
available virtual address space on a 32 bit OS which predicts the amount of
memory you can allocate. No single process, unless very carefully designed
and tested, will run for long before it encounters OOM exceptions when you
start allocating large objects or huge array's at wild. That's why asp.net
(the hosting process) provides the possibility to restart an AD and or the
worker process when a configurable memory threshold has been reached.

Willy.

Sep 26 '06 #7
Thanks for your answer!

I want to upload an image to a web application and therefore i need to
allocate this memory to fill the byte array with image data. Then I
need to do a resizing operation.

Ignacio Machin ( .NET/ C# MVP ) schrieb:
Hi,
"Gerrit" <Ge***********@ web.dewrote in message
news:11******** **************@ h48g2000cwc.goo glegroups.com.. .
Hi all,

I'm getting an OutOfMemoryExce ption when I initialize a byte array in
C# like this:

Byte[] test = new Byte[420000000];

I'm using ASP.NET 2.0. In ASP.Net 1.1 it works fine. So what am I doing
wrong?

What is the maximum length of a byte array?


Why you need such a big array in the first place?

I bet it depends of either (or both) IIS and the framework

--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Sep 26 '06 #8
I think I'll try your advice at home where I have a 64Bit system but
with WinXP 32Bit OS installed. Do I also need to install a 64Bit OS to
try that ? (would be a task for the weekend ;-))
Thomas Scheidegger [MVP] schrieb:
The strange on this behavior is that it sometimes occurs and sometimes not.


I guess it could also be some fragmentation of heaps / virtual address space.

=Get a 64-Bit system ;-) {but even 64-Bit .NET 2.0 has some 32-Bit limitations }

http://blogs.msdn.com/tess/archive/2...25/496898.aspx

http://msdn.microsoft.com/library/en...nitor_perf.asp
--
Thomas Scheidegger - MVP .NET - 'NETMaster'
http://www.cetus-links.org/oo_dotnet.html - http://dnetmaster.net/
Sep 26 '06 #9
>I think I'll try your advice at home where I have a 64Bit system but
with WinXP 32Bit OS installed. Do I also need to install a 64Bit OS to
try that ? (would be a task for the weekend ;-))

yes both, 64-Bit Windows (XP/2003/[Vista])
and the 64-Bit .NET Runtime.
For x64:
http://www.microsoft.com/downloads/d...B-40E78D788B00

And compile for 'AnyCpu' target (or x64).

And maybe switching ASP.NET to 64-Bit
http://support.microsoft.com/kb/894435/en-us


--
Thomas Scheidegger - MVP .NET - 'NETMaster'
http://www.cetus-links.org/oo_dotnet.html - http://dnetmaster.net/
Sep 26 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
25373
by: eggie2486 | last post by:
What is the maximum size of an array? I tried to edit an extremely large array for a magic square, for example, array, and when I ran the program, it would not display the array. I changed the array to 105 by 105 and it worked fine. Does anybody know what the problem is and how I could possibly get around it?
2
28545
by: Kums | last post by:
What is the maximum permissible size of a database? Is there any limitation. What is the maximum # of tablespace's allowed in a database? Thanks for your response.
5
7809
by: Orange | last post by:
hi, How to initialize the data variable. typedef struct { long len; BYTE data; }tag;
8
11641
by: piggy | last post by:
I am trying to convert an image to an byte array (tobytes() method) and from byte array back to an image (frombytes() method). The problem i have here is say the image size is 285 bytes but the total bytes is 635. I know it would include the header but the header should be the same size regardless of the image size. I tested the other image...
5
4350
by: Gerrit | last post by:
Hi all, I'm getting an OutOfMemoryException when I initialize a byte array in C# like this: Byte test = new Byte; I'm using ASP.NET 2.0. In ASP.Net 1.1 it works fine. So what am I doing
1
10403
by: O.B. | last post by:
In the example below, I'm trying to convert a fixed byte array to a string. I get an error about needing to use "fixed" but I have no clue where to apply it. Help? using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices;
1
9293
by: | last post by:
Hi all, I am writing a sendmail milter application in Java. The incoming mails will usually have image file as attachments. My application is currently able to extract the ImageFile and save it on the filesystem. This part is working perfectly. ((MimeBodyPart)p).saveFile(new File(p.getFileName())); However, I would like to pass this...
3
18188
by: skyy | last post by:
Hi.. what is the maximum size of an array and variable? With the following declaration: my $size; my @rx_array; what is the maximum number that $size can hold? what is the maximum number of elements @rx_array can hold?
10
6355
by: Scott Townsend | last post by:
So I need to talk to a devices that expects all of the bits and bytes I sent it to be in specific places (not yet 100% defined). I wanted to create a structure/class with all of the data in it and then convert that to a byte array, pass it to the device, then get a reply and then convert that to a structure. I'm having issues with making...
10
24639
by: Chunekit Pong | last post by:
I have a BYTE array - BYTE const* pbBinary I would like to know how many bytes in that byte array but if I do - sizeof(* pbBinary); - then I got 1 but if I do - sizeof( pbBinary); - then I got 4 I am sure the array has hundreds of bytes
0
7626
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7549
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7591
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6180
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5172
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3599
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3577
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1161
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.