|
i'm not sure if i am right but:
an int32 wont hold more than about 4.000.000.000 (somewhere "near" that)
1024*1024*200 will result more than 20.000.000.000 so you should try to use
1. unsigned variables
2. bigger variables
the last time i had to use 64-bit variables, they were no operators for multiplications and division available so you will have to "work around".
|
|
|
|
|
mikone wrote: 1024*1024*200 will result more than 20.000.000.000
;P
|
|
|
|
|
uhh yeah, excuse me. i was at work so my brain was kinda turned off
so yeah, that definitely would fit an 32-bit integer (200.000.000)
next time i should use a calculator just to make sure such an emberassing thing doesn't happen again (but as i already said: i was at work, you can't blame me )
|
|
|
|
|
I put the wrong code in the post. This is what I was thinking about:
it works:
int[] values1 = new int[1024*1024*50]
int[] values2 = new int[1024*1024*50]
it gives OutOfMemoryException:
int[] values1 = new int[1024*1024*100]
There is enough free memory to allocate even 1Gb, but the problem for .NET is that there is no continous area of the memory which size is 400Mb. This is why I can allocate two times 200Mb but I can not allocate 400 Mb once. The question is: Can it be avoided somehow?
pawelpus
|
|
|
|
|
there is another answer to this question already - i will sum it up:
you're creating an array of integers whichs elements are 4 byte big. thats why you should change it to
<br />
byte[] values = new byte[1024*1024*100];<br />
|
|
|
|
|
Hi,
byte[] values = new byte[1024*1024*100]
The above code line needs 100 Mb of the memory
int[] values = new byte[1024*1024*25]
The above code line needs 100 Mb of the memory.
The point is that I can not allocate on my machine 400 Mb in any way.The code with byte[]..gives the same resuls as the code with int[]..
pawelpus
|
|
|
|
|
<br />
byte[] values = new byte[1024*1024*1231];<br />
Console.WriteLine(values.Length.ToString());<br />
Console.ReadKey(); <br />
this code produces the following output:
<br />
1290797056<br />
when i tried
<br />
byte[] values = new byte[1024*1024*1231];<br />
the same exception occured.
that means i was able to allocate 1231 mb...
|
|
|
|
|
On my machine both are giving me an OutOfMemoryException.
Integers have 4 Bytes so int[] values1 = new int[1024*1024*400]; will allocate not 400 MB but 1600MB. The logical memory limit of Windows 32 bit per process is somewhere near 2GB and I think .Net crunches away some of this.
Thus you are really reaching the limit...
|
|
|
|
|
I put the wrong code in the post. This is what I was thinking about:
it works:
int[] values1 = new int[1024*1024*50]
int[] values2 = new int[1024*1024*50]
it gives OutOfMemoryException:
int[] values1 = new int[1024*1024*100]
There is enough free memory to allocate even 1Gb, but the problem for .NET is that there is no continous area of the memory which size is 400Mb. This is why I can allocate two times 200Mb but I can not allocate 400 Mb once. The question is: Can it be avoided somehow?
pawelpus
|
|
|
|
|
An int is 4 bytes. It is a synonym for Int32 . Thus you are allocating ~1.6Gb.
Try creating a byte[] instead
|
|
|
|
|
I put the wrong code in the post. This is what I was thinking about:
it works:
int[] values1 = new int[1024*1024*50]
int[] values2 = new int[1024*1024*50]
it gives OutOfMemoryException:
int[] values1 = new int[1024*1024*100]
There is enough free memory to allocate even 1Gb, but the problem for .NET is that there is no continous area of the memory which size is 400Mb. This is why I can allocate two times 200Mb but I can not allocate 400 Mb once. The question is: Can it be avoided somehow?
pawelpus
|
|
|
|
|
I would like to make an exe dependent on another exe i.e when program a.exe is started program b.exe should also start and when program a.exe terminates program b.exe should also terminate.
Is that possible?
How could I make it happen?
|
|
|
|
|
On Load form of ur a.exe programm start b.exe program
On Close from of ur a.exe programm kill process of b.exe program
|
|
|
|
|
when program A starts, it could create a System.Diagnostics.Process object at startup and start the other programm. Since programs sometimes doesn't shut down when and as they were meant to, there is no guarantee that the "cleanup" code will get executed so the answer to your question would be yes and no...
|
|
|
|
|
Hi All,
I have a DataTable in cache object and a local Datatable populated by calling an SP. I need to compare the whole data in both DataTables.If Cache DataTable's data is old then refresh it with latest one by calling the SP again and then use it later on.
How can I achieve this ?
Pls guide me.
Thanks
Omkar
|
|
|
|
|
You also posted this in the SQL message boards. Please do not cross-post.
|
|
|
|
|
Hi I'm using the SerialPort class (.net 2.0) for rs232 communications. Unfortunately, an it freezes up my program when I try to set a parameter for it after it's been opened.
First I initialize the port:
SerialPort port = new SerialPort(comname, 19200);
port.Open();
port.ReceivedBytesThreshold = 63;
port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
Then I do some communications stuff. So far so good. The freeze occurs when I try to use the port for some other process.
if (port.IsOpen)
{
port.DiscardInBuffer();
port.DiscardOutBuffer();
port.Close();
}
port.ReceivedBytesThreshold = 1;
port.Open();
Any of the commented line freeze up my program as if in a blocking state, and the code doesn't throw an exception of any kind, it just freezes each and any thread currently running. Does anyone have any clues what's happening here?
|
|
|
|
|
Ok, I already found the problem, for some strange reason the port needs to be reconstructed:
port = new SerialPort(port.PortName, port.Baudrate);
Weird...
|
|
|
|
|
Not Wierd. You'll actually find that this happens throughout the Framework. Try looking at the Font class for another example of immutable, or partially immutable, objects.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi All
I am trying to use
string searchPattern;
Directory.GetFiles(@"C:\myDirectory", searchPattern);
but I want to make my search pattern include certain types for example *.jpeg and *.htm and so on .....
How to implement this
|
|
|
|
|
if it works like the filter for openfiledialog it should be enough to pass a string like
"*.jpeg|*.htm|*.html" - if not you could easily write it by yourself.
<br />
searchpattern[0] = "*.jpeg";<br />
searchpattern[1] = "*.html";<br />
searchpattern[n] = ...;<br />
<br />
FileInfo filelist[n];<br />
<br />
<br />
for (int i = 0; i < searchpattern.GetLength(0) -1; i++)<br />
{<br />
filelist[i] = Directory.GetFiles("C:\WhatEver", searchpattern[i]);<br />
}<br />
<br />
Since I haven't had to do anything similar there may be a built-in function (for passing multiple searchpattern) i dont know of...
Good luck,
mik
|
|
|
|
|
GetFiles only works with one wildcard pattern. If you want to return varying patterns, like "*.jpg" and "*.bmp" you'll have to make seperate calls to GetFiles, one for each pattern you want to use.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
|
Here's something I coded up a few weeks ago:
public IEnumerable<string> GetFilesInDirectory(string directory, SearchOption searchOptions, params string[] filters)
{
foreach (string matchingFile in Directory.GetFiles(directory, "*.*", searchOptions))
{
if(EndsWithAny(matchingFile, filters))
{
yield return matchingFile;
}
}
}
bool EndsWithAny(string text, string[] endings)
{
foreach(string ending in endings)
{
if(text.EndsWith(ending))
{
return true;
}
}
return false;
}</string>
You can use it like this:
foreach(string jpgOrHtmFile in GetFilesInDirectory("c:\\myDir", SearchOption.AllDirectories, ".jpg", ".htm"))
{
Console.WriteLine(jpgOrHtmFile);
}
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Dumbest. Movie. Title. Evaaar.
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
many thx Judah
it works good
|
|
|
|