Help--My Array is too Big-----Help move to a .dat file?

  • Thread starter Thread starter Yogi_Bear_79
  • Start date Start date
Y

Yogi_Bear_79

Visual Studio .NET started complaing when the array was around 4000. I
found that if I pasted the array in via notepad then opened Visual Studio it
would work. Now my array is over 26,000 and Visual Studio just doesn't like
it. Everytime I open the prokect I get the following error:

"An Error occurred which the C# comipler is unable to report due to low
memory or possible heap corruption. It is recommended that you save all your
files, close and restart"

If I wait for about 60 seconds I can use the program as long as I stay out
of the class with that array (about 633kb).

So I think it's time to move the array out to another file. So Can anyone
help me out here? I am thinking a .dat file or any other file that a user
can't simply open and read would be my first choice. Else I wopuld resort to
a plain old text file.
 
Why not use an Excel Spreadsheet? It will address much
the same logic as an array and you may be able to use the
spreadhseet functions too.
 
That is a viable solution. In fact I maintain my ARRAY lists in an Excel
sheet prior to importing them into the program. I originally imported them
to make it one stand alone .exe file. Now it seems to out growing that. So
the thought of an external file comes to mind. A Excel file would yeild much
the same results as a .txt. or .csv. I though of the .dat file because all
the ones I've seen associated with programs you can't simply open and
read/modify.


An Excel file and the others mentiod would be open to the user. I have
seen many programs that have a few program files, then they update the .dat
files when new info comes out. I always liked this approach.
 
Yogi_Bear_79 said:
Visual Studio .NET started complaing when the array was around 4000. I
found that if I pasted the array in via notepad then opened Visual Studio it
would work. Now my array is over 26,000 and Visual Studio just doesn't like
it. Everytime I open the prokect I get the following error:

"An Error occurred which the C# comipler is unable to report due to low
memory or possible heap corruption. It is recommended that you save all your
files, close and restart"

If I wait for about 60 seconds I can use the program as long as I stay out
of the class with that array (about 633kb).

So I think it's time to move the array out to another file. So Can anyone
help me out here? I am thinking a .dat file or any other file that a user
can't simply open and read would be my first choice. Else I wopuld resort to
a plain old text file.

What's it an array of? You might find that BinaryReader/BinaryWriter is
the way to go. If the array is pre-defined (as presumably it is), you
could embed the content into the assembly to make it easier for the
user.
 
What's it an array of? You might find that BinaryReader/BinaryWriter is
the way to go. If the array is pre-defined (as presumably it is), you
could embed the content into the assembly to make it easier for the
user.


The array is a predefined list of web sites, and another of ActiveX CLSIDs.

The Array of web sites is over 26,000 elements, and the ActiveX is over
1300. When you say I could embed the content into the assembly, what does
that mean? Does it mean I could use binary to represent my arrays, and
compile it into the executable, thus keeping my single file? I would love
that. As my arrays grew my program grew from 233kb to 1.4Mb, so with the
advent of Visual Studio complaining about my large class, I thought it best
to move the arrays out of the compiled program, and manage them in seperate
files. But If I went that route I'd like to see them "encoded" for lack of a
better word. Ultimatly I would rather leave them within the compiled .exe
tho
 
I would think an .xml file would also work, but I beleive it has the same
pros & cons as the other files listed below?
What do you think?
 
Yogi_Bear_79 said:
The array is a predefined list of web sites, and another of ActiveX CLSIDs.

The Array of web sites is over 26,000 elements, and the ActiveX is over
1300. When you say I could embed the content into the assembly, what does
that mean? Does it mean I could use binary to represent my arrays, and
compile it into the executable, thus keeping my single file? I would love
that. As my arrays grew my program grew from 233kb to 1.4Mb, so with the
advent of Visual Studio complaining about my large class, I thought it best
to move the arrays out of the compiled program, and manage them in seperate
files. But If I went that route I'd like to see them "encoded" for lack of a
better word. Ultimatly I would rather leave them within the compiled .exe
tho

What you'd do is create a text file (or something similar) and put that
in your VS.NET project as a resource with a property telling it to make
it an embedded resource. You'd then need to use
Assembly.GetManifestResourceStream to open the file, read it into your
array (or ArrayList) at runtime and then you're "good to go".
 
What you'd do is create a text file (or something similar) and put that
in your VS.NET project as a resource with a property telling it to make
it an embedded resource. You'd then need to use
Assembly.GetManifestResourceStream to open the file, read it into your
array (or ArrayList) at runtime and then you're "good to go".

Before I begin, let me thank you for your time. I am a self learned
programmer, I do it to streamline some of my workload as a systems
administrator. So I am on a slow curve, as I use the net, books, and NG to
learn. I have not taken any classes.

Ok. I created and set to embedded a .txt file called Sites.txt

My original program was setup like this

private string [] sResSitesList= {"008i.com", "008k.com", "00hq.com",
"0190-dialer.com"};
public string []strResSitesList
{
get { return sResSitesList; }
set { sResSitesList = value; }
}

Then I would access the Array from another class:
foreach(string x in strResSitesList)
{
using (RegistryKey Key = Registry.LocalMachine.CreateSubKey( x )
{
Key.SetValue ("*", Convert.ToInt32(00000004));
}

}



How do I now access my list from the .txt file, and if you could explain the
benifit of this method I would appriciate it. I usually need code examples
to learn new ideas, so I can see how it works..I am also willing to read, I
am doing google searches as we speak
 
Yogi_Bear_79 said:
in your VS.NET project as a resource with a property telling it to make
it an embedded resource. You'd then need to use
Assembly.GetManifestResourceStream to open the file, read it into your
array (or ArrayList) at runtime and then you're "good to go".

Before I begin, let me thank you for your time. I am a self learned
programmer, I do it to streamline some of my workload as a systems
administrator. So I am on a slow curve, as I use the net, books, and NG to
learn. I have not taken any classes.

Ok. I created and set to embedded a .txt file called Sites.txt

My original program was setup like this

private string [] sResSitesList= {"008i.com", "008k.com", "00hq.com",
"0190-dialer.com"};
public string []strResSitesList
{
get { return sResSitesList; }
set { sResSitesList = value; }
}

Then I would access the Array from another class:
foreach(string x in strResSitesList)
{
using (RegistryKey Key = Registry.LocalMachine.CreateSubKey( x )
{
Key.SetValue ("*", Convert.ToInt32(00000004));
}

}

How do I now access my list from the .txt file, and if you could explain the
benifit of this method I would appriciate it. I usually need code examples
to learn new ideas, so I can see how it works..I am also willing to read, I
am doing google searches as we speak

Well, you'd read it like a normal text file, so you'd use something
like:

ArrayList resourceSites = new ArrayList();

using (Stream stream=GetType().Assembly.GetManifestResourceStream(...))
{
using (StreamReader reader = new StreamReader(stream))
{
string line;
while ( (line=reader.ReadLine()) != null)
{
resourceSites.Add(line);
}
}
}

Then you'd need to create the text file, put it into the solution, and
make the build action "embedded resource". Then just make sure that you
get the right name in the call to GetManifestResourceStream, and it'll
all work.
 
I'm getting there. The code compiles without error. But I can't get any
output from my array. I attempted to do a Console.Writeline on each element
of the array to see it's output. I get no errors, but nothing shows in my
console window.

Here is my test class

using System;
using System.Collections;
using System.IO;
using System.Reflection;
using Microsoft.Win32;

namespace Build_Script
{
public class RestrictSites
{

private ArrayList resourceSites = new ArrayList();

public RestrictSites()
{
AddRestrictedSites();
}


private void AddRestrictedSites()
{

using (Stream
stream=GetType().Assembly.GetManifestResourceStream("Build_Script.Sites.txt"
))
{
using (StreamReader reader = new StreamReader(stream))
{
string line;
while ( (line=reader.ReadLine()) != null)
{
resourceSites.Add(line);
}
}
}
foreach(string x in resourceSites)
{
Console.WriteLine(x);
}
}

}
}
 
Yogi_Bear_79 said:
I'm getting there. The code compiles without error. But I can't get any
output from my array. I attempted to do a Console.Writeline on each element
of the array to see it's output. I get no errors, but nothing shows in my
console window.

So what happens when you run it in the debugger, looking at what lines
you're trying to add?

Are you definitely not getting any exceptions? (I can imagine you could
have an error with the "Build_Script.Sites.txt" part - that's easy to
do.)
 
Ok it was my bad, duh start without debugging does just what it says!!!!

Now my questions :)

I tested this on an older version of my program with a much smaller list
5212. I got a net decrese of 8% in the compiled file size. That isn't going
to be much when I apply this to my current version. I am at home today, so I
do not have my current source files with me. So what benifits are derived
from this method over my previous one?

These are the ones I can see:

1. I can see the .txt file is 20% smaller than the original class that held
the array.
2. The .txt file is easier to manipulate than the .cs was
3. I can still compile into a single executable file.

Is there a more compact way of storing my list? Currently I have one site
per line in a standard.txt file. Is there a way to store this list in an
even smaller format?





"> So what happens when you run it in the debugger, looking at what lines
 
Ok I'm an idiot. The first time I ran in debuggin mode I got two windows at
the bottom, the right one showed my console.writeline results... Now I can
not figure out what window it was to repeat this. I need to repeat so I can
concatinate the array ti a string
 
Yogi_Bear_79 said:
Ok it was my bad, duh start without debugging does just what it says!!!!

Now my questions :)

I tested this on an older version of my program with a much smaller list
5212. I got a net decrese of 8% in the compiled file size. That isn't going
to be much when I apply this to my current version. I am at home today, so I
do not have my current source files with me. So what benifits are derived
from this method over my previous one?

These are the ones I can see:

1. I can see the .txt file is 20% smaller than the original class that held
the array.
2. The .txt file is easier to manipulate than the .cs was
3. I can still compile into a single executable file.

Here, 2) is the primary one, and also the fact that it gets round your
original problem of not being able to compile. In addition, you may
find that type loading is quicker as it won't need to populate the
array until you actually need it.
Is there a more compact way of storing my list? Currently I have one site
per line in a standard.txt file. Is there a way to store this list in an
even smaller format?

Is the size of your executable really that important? I mean you
*could* zip the file and then unzip it (in memory) as you read it,
using something like SharpZipLib. That would be significant extra work
though.
 
Ok, I am with you.

The size of the .exe isn't a big deal right now, as it's 1.4Mb. It will
decrease with the replacement of the Array Classes with the .txt files. My
primary method of distribution is e-mail to the dozen or so people who use
my program. SO keepign it small is ideal.

I was able to compile before, the Visual Studio .Net program gave me the
error in my original post upon opening, if I stayed out of the Array
Class(s) I was fine and it would re-compile.

I am thinking since I don't need to see the txt files, I can hide them but
keep them in the solution. That should alliviate the slowness I was seeing.
I am going to read up on the SharpZipLib idea. Mainly because I saw a 75%
decrease in file size when I zipped my text file.
 
Back
Top