I have to initialize a huge constant array of structures(60000~100000),
used as a lookup table , but it failed with
System.InvalidProgramException
when the items reach 18400. and if I change the item type from struct
to class,
the threshold is 35000 . It seems that there a size limition when
initialize constant in CLR.
Is there any configurable parameters can be used to increase this
limition in C# compiler
or .NET framework. Or I'm missing something there?
using System;
struct st
{
public short t1,t2 ;
public st(short t1,short t2){
this.sym = t1;
this.act = t2;
}
}
class Test{
static void Main(){
st[] a = {
new st(3,4),
new st(3,4),
new st(3,4),
new st(3,4),
new st(3,4),
new st(3,4),
new st(1,2),
...
...
repeated more than 20000 times
...
...
...
new st(3,4),
new st(1,2),
new st(1,2),
new st(3,4),
new st(1,2),
new st(1,2),
new st(3,4)
};
Console.WriteLine("{0}",a[1].t1);
}
} 3 2108
<dp*****@gmail.com> wrote: I have to initialize a huge constant array of structures(60000~100000), used as a lookup table , but it failed with System.InvalidProgramException when the items reach 18400. and if I change the item type from struct to class, the threshold is 35000 . It seems that there a size limition when initialize constant in CLR. Is there any configurable parameters can be used to increase this limition in C# compiler or .NET framework. Or I'm missing something there?
This really isn't the best way of accomplishing your task. It would be
much better to load the data from a stream (whether an embedded
resource or an external file). That way you won't run into this limit,
and your code will be a lot simpler too!
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Thanks for your help.
It seems a good solution to use embedded resource file to manage this
big arrays.
But there is another problem when getting back this array back from
resource file.
there is always a System.InvalidCastException for this line:
st[] a = (st[]) rm.GetObject("array 1",ci);
can anyone help?
It's ok to create a resource file using following code:
using System;
using System.Resources;
[Serializable]
struct st
{
public short t1,t2 ;
public st(short t1,short t2){
this.t1 = t1;
this.t2 = t2;
}
}
public class WriteResources {
public static void Main(string[] args) {
st[] a = {
new st(3,4),
new st(3,4),
new st(3,4),
new st(3,4),
new st(3,4),
new st(3,4)
};
// Creates a resource writer.
IResourceWriter writer = new
ResourceWriter("myResources.resources");
// Adds resources to the resource writer.
writer.AddResource("String 1", "First String");
writer.AddResource("array 1", a);
writer.Generate();
// Writes the resources to the file or stream, and closes it.
writer.Close();
}
}
but failed when retrieve array back from the resource file,
using System;
using System.Resources;
using System.Collections;
using System.Globalization;
using System.Threading;
using System.Reflection;
[Serializable]
struct st
{
public short t1,t2 ;
public st(short t1,short t2){
this.t1 = t1;
this.t2 = t2;
}
}
class EnumerateResources
{
public static void Main()
{
// Create a resource manager to retrieve resources.
ResourceManager rm = new ResourceManager("myResources",
Assembly.GetExecutingAssembly());
CultureInfo ci = Thread.CurrentThread.CurrentCulture;
//It's ok to retrieve string
String str = rm.GetString("String 1", ci);
Console.WriteLine(str);
//THERE IS ALWAYS A System.InvalidCastException for this line:
st[] a = (st[]) rm.GetObject("array 1",ci);
Console.WriteLine(a[1].t1);
}
}
<dp*****@gmail.com> wrote: It seems a good solution to use embedded resource file to manage this big arrays.
But there is another problem when getting back this array back from resource file.
there is always a System.InvalidCastException for this line:
st[] a = (st[]) rm.GetObject("array 1",ci);
can anyone help?
It's ok to create a resource file using following code:
Well, I can't say I've used the ResourceManager much myself. I was
suggesting using it just as an embedded file, getting the stream from
the assembly and then reading it in manually. Hopefully someone else
will have more experience with ResourceManager though.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: SamMan |
last post by:
Is there an easy way to re-initialize an array, other than looping through
it's length and setting the values to null, or ""? Would unset() be a wise
choice?
Thanks again
--
SamMan
|
by: Andi.Martin |
last post by:
Hi,
how is it possible, to only initialize parts of a structure.
Example:
typedef struct{
int a, b;
... (huge lot of members);
double x,y;
|
by: Gustavo L. Fabro |
last post by:
Greetings!
I'm testing VS 2005 Beta 2, and I've compiled a program that
runs just fine on my computer (where VS is installed).
I've tried to run this same program on another computer
(after...
|
by: Michael Gray |
last post by:
VS 2003
VB.net
Win2000 SP4
The System.Array class seems to be limited to 32 bit addresses,
meaning that one can only assign 2^32 elements.
Is there any way that I can have an array that...
|
by: dpriver |
last post by:
I have to initialize a huge constant array of structures(60000~100000),
used as a lookup table , but it failed with
System.InvalidProgramException
when the items reach 18400. and if I change the...
| |
by: Peter Steiner |
last post by:
I have written a Service in C++ (VC8) derived from
System::ServiceProcess::ServiceBase.
In the OnStart() method I detect a service failure but the SCM reports that
the service started...
|
by: Benny Raymond |
last post by:
Basically what the subject says...
"in a bool 2d array, does Initialize set everything to false?"
|
by: deko |
last post by:
I trying to create a jagged array of two arrays, with the second array being
an array of two-dimensional arrays.
A graphical representation might look like this:
x y y y
x y
x y y
x ...
|
by: Jason |
last post by:
I am attempting to have an asp page call a batch file.
I had it working, I was high on life and then I decided to log off the
server. Once I did, the code would no longer work. When I logged back...
|
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,...
|
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...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |