473,396 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Maximum Size of Byte Array

Hi all,

I'm getting an OutOfMemoryException 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
5 4340
ASP.Net 2.0 could be protecting the memory of the server better. That's a
400 MB byte array, which for a lot of servers could be 20% of the available
memory if not more. That could be fine for one and only one user and page
instance, but what happens if even two users work the code that requires a
400 MB byte array allocated. I'm not exactly sure if that's a feasible array
size for a server environment which could be why it's not letting you do it.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"Gerrit" <Ge***********@web.dewrote in message
news:11**********************@d34g2000cwd.googlegr oups.com...
Hi all,

I'm getting an OutOfMemoryException 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 #2
Thank you for your advice!

But I need to use this big array. In my application I want to generate
thumbs and previews from uploaded images and I do not expect that these
images are greater than 100MB in normal case. But in some cases these
images can be about 1 GB. (Perhaps every 6 Month...)

My PC has 2,5 GB of RAM and it's although not able to generate this
array. What do I have to do to make this possible. Is there any system
property in the machine.conig or something else I could do?

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
Mark Fitzpatrick schrieb:
ASP.Net 2.0 could be protecting the memory of the server better. That's a
400 MB byte array, which for a lot of servers could be 20% of the available
memory if not more. That could be fine for one and only one user and page
instance, but what happens if even two users work the code that requires a
400 MB byte array allocated. I'm not exactly sure if that's a feasible array
size for a server environment which could be why it's not letting you do it.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"Gerrit" <Ge***********@web.dewrote in message
news:11**********************@d34g2000cwd.googlegr oups.com...
Hi all,

I'm getting an OutOfMemoryException 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 #3
Gerrit:
I got a good laugh out of this one :)

You can change ASP.NET to use more memory in the processModel...it's set to
60% by default...you can up it..but you'll run into a win32 2gig process
limit (60% of 2.5 is 1.5..so you might be able to get 1.8..but I wouldn't
push it more than that).

Seriously though, some suggestions:

1 - Atleast consider a generic List<Byte which can have it's size
allocated dynamically..so if you only need 100 mb's, you don't need to
allocate any more.
2 - Is it at all possible to process these images in smaller chunks? or do
you need to do everything all at once?

Also, I THINK depending on where this is defined, the allocation might
happen on the stack instead of the heap...which is much smaller. I'm just
guessing here. I'm I'm right, you'd certainly run up against a limit at 420
megs. The solution might be to define test as an object field...which will
then make it get allocated on the heap..

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Gerrit" <Ge***********@web.dewrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Thank you for your advice!

But I need to use this big array. In my application I want to generate
thumbs and previews from uploaded images and I do not expect that these
images are greater than 100MB in normal case. But in some cases these
images can be about 1 GB. (Perhaps every 6 Month...)

My PC has 2,5 GB of RAM and it's although not able to generate this
array. What do I have to do to make this possible. Is there any system
property in the machine.conig or something else I could do?

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
Mark Fitzpatrick schrieb:
>ASP.Net 2.0 could be protecting the memory of the server better. That's a
400 MB byte array, which for a lot of servers could be 20% of the
available
memory if not more. That could be fine for one and only one user and page
instance, but what happens if even two users work the code that requires
a
400 MB byte array allocated. I'm not exactly sure if that's a feasible
array
size for a server environment which could be why it's not letting you do
it.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"Gerrit" <Ge***********@web.dewrote in message
news:11**********************@d34g2000cwd.googleg roups.com...
Hi all,

I'm getting an OutOfMemoryException 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 #4
Thank you for your answer!

I had already setup this setting in the processmodel-section to 90% but
there is still the same behavior.

If I allocate a 400 MB byte array I Do need this axact size because the
file has this size. I do not allocate 400 MB in every case of course.

The idea to trade the image in chunks is very good.
But I do not know how to load an image in chunks into memory, which
could be compressed (perhaps a jpeg file).

I probably have to decompress this chunk and convert it into a Bitmap
and then save it to Harddisk as chunk "xy".

Is it even possible to work with a compressed chunk of a jpeg file? How
can I determine wich size (height and width) this chunk has (I would
need this info to put the chunks together again after resizing them)

sorry for so many questions...But perhaps you can help again...

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

Karl Seguin [MVP] schrieb:
Gerrit:
I got a good laugh out of this one :)

You can change ASP.NET to use more memory in the processModel...it's set to
60% by default...you can up it..but you'll run into a win32 2gig process
limit (60% of 2.5 is 1.5..so you might be able to get 1.8..but I wouldn't
push it more than that).

Seriously though, some suggestions:

1 - Atleast consider a generic List<Byte which can have it's size
allocated dynamically..so if you only need 100 mb's, you don't need to
allocate any more.
2 - Is it at all possible to process these images in smaller chunks? or do
you need to do everything all at once?

Also, I THINK depending on where this is defined, the allocation might
happen on the stack instead of the heap...which is much smaller. I'm just
guessing here. I'm I'm right, you'd certainly run up against a limit at 420
megs. The solution might be to define test as an object field...which will
then make it get allocated on the heap..

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Gerrit" <Ge***********@web.dewrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Thank you for your advice!

But I need to use this big array. In my application I want to generate
thumbs and previews from uploaded images and I do not expect that these
images are greater than 100MB in normal case. But in some cases these
images can be about 1 GB. (Perhaps every 6 Month...)

My PC has 2,5 GB of RAM and it's although not able to generate this
array. What do I have to do to make this possible. Is there any system
property in the machine.conig or something else I could do?

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
Mark Fitzpatrick schrieb:
ASP.Net 2.0 could be protecting the memory of the server better. That's a
400 MB byte array, which for a lot of servers could be 20% of the
available
memory if not more. That could be fine for one and only one user and page
instance, but what happens if even two users work the code that requires
a
400 MB byte array allocated. I'm not exactly sure if that's a feasible
array
size for a server environment which could be why it's not letting you do
it.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"Gerrit" <Ge***********@web.dewrote in message
news:11**********************@d34g2000cwd.googlegr oups.com...
Hi all,

I'm getting an OutOfMemoryException 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 27 '06 #5
Gerrit:
Unfortunetly I don't know enough about the jpg image format...

I know bitmaps are just an array of X/Y RGBA pixels..

It'd be nice if GDI+ took care of doing this for you, but from my brief
research, it looks like it's an all or nothing scenario...

The only thing I can recommend is that you try to take a look through:
http://groups.google.ca/groups/searc...es&qt_s=Search

I took a quick look and didn't find anything promising though :(

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Gerrit" <Ge***********@web.dewrote in message
news:11*********************@b28g2000cwb.googlegro ups.com...
Thank you for your answer!

I had already setup this setting in the processmodel-section to 90% but
there is still the same behavior.

If I allocate a 400 MB byte array I Do need this axact size because the
file has this size. I do not allocate 400 MB in every case of course.

The idea to trade the image in chunks is very good.
But I do not know how to load an image in chunks into memory, which
could be compressed (perhaps a jpeg file).

I probably have to decompress this chunk and convert it into a Bitmap
and then save it to Harddisk as chunk "xy".

Is it even possible to work with a compressed chunk of a jpeg file? How
can I determine wich size (height and width) this chunk has (I would
need this info to put the chunks together again after resizing them)

sorry for so many questions...But perhaps you can help again...

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

Karl Seguin [MVP] schrieb:
>Gerrit:
I got a good laugh out of this one :)

You can change ASP.NET to use more memory in the processModel...it's set
to
60% by default...you can up it..but you'll run into a win32 2gig process
limit (60% of 2.5 is 1.5..so you might be able to get 1.8..but I wouldn't
push it more than that).

Seriously though, some suggestions:

1 - Atleast consider a generic List<Byte which can have it's size
allocated dynamically..so if you only need 100 mb's, you don't need to
allocate any more.
2 - Is it at all possible to process these images in smaller chunks? or
do
you need to do everything all at once?

Also, I THINK depending on where this is defined, the allocation might
happen on the stack instead of the heap...which is much smaller. I'm just
guessing here. I'm I'm right, you'd certainly run up against a limit at
420
megs. The solution might be to define test as an object field...which
will
then make it get allocated on the heap..

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Gerrit" <Ge***********@web.dewrote in message
news:11**********************@m73g2000cwd.googleg roups.com...
Thank you for your advice!

But I need to use this big array. In my application I want to generate
thumbs and previews from uploaded images and I do not expect that these
images are greater than 100MB in normal case. But in some cases these
images can be about 1 GB. (Perhaps every 6 Month...)

My PC has 2,5 GB of RAM and it's although not able to generate this
array. What do I have to do to make this possible. Is there any system
property in the machine.conig or something else I could do?

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
Mark Fitzpatrick schrieb:

ASP.Net 2.0 could be protecting the memory of the server better.
That's a
400 MB byte array, which for a lot of servers could be 20% of the
available
memory if not more. That could be fine for one and only one user and
page
instance, but what happens if even two users work the code that
requires
a
400 MB byte array allocated. I'm not exactly sure if that's a feasible
array
size for a server environment which could be why it's not letting you
do
it.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"Gerrit" <Ge***********@web.dewrote in message
news:11**********************@d34g2000cwd.googleg roups.com...
Hi all,

I'm getting an OutOfMemoryException 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 27 '06 #6

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

Similar topics

11
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...
2
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.
11
by: Walter Dnes (delete the 'z' to get my real address | last post by:
I've noticed a few threads (full of sound and fury, signifying nothing) here recently about allocation of large memory blocks. I'm about to start on a personal pet project where I'll be using...
1
by: Jón Sveinsson | last post by:
Hello everyone I have been trying to read and write struct to binary files, I'm using to functions to convert the struct to bytes and bytes to struct, I always receive the following error ...
4
by: Gregory Hassett | last post by:
Hello, Does anyone know how to get the maximum size of a datagram for a UDP Socket created via .NET's System.Net.Sockets.Socket class? Thanks!
23
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...
2
choke
by: choke | last post by:
I need to write a function in devc++ that creates an array of n integers, each element is equal to n*n+i*i-n*i where i is from 0 to n-1 as the array index. Within the same function I need to find...
18
by: raylopez99 | last post by:
The maximum int for an array on my machine (a Pentium IV with 2 GB RAM) is < 330 Million...before you get an "out of memory" exception. I simply filled an array of this size with ints...I got as...
10
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.