|
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
|
|
|
|
|
Hi
I have an SQL query which can be run in the Microsoft Visual C# 2005 Express Edition. But when I put that query in my program, it doesn't get run and it throws an exception saying "No given value for one or more required parameters".
Anybody knows how it could happen?
Thanks
|
|
|
|
|
printscreen12345 wrote: "No given value for one or more required parameters". Anybody knows how it could happen?
Just a guess, but I'd say you have parameters in your SQL statement that are not being set.
only two letters away from being an asset
|
|
|
|
|
it would be useful to:
- know the query
- know what you mean when talking about "my program"
did you ever read this "how to ask questions the smart way"-guide? :P
|
|
|
|
|
did you try to debug your application and then take the generated SQL query to execute directly on SQL Server or "Server Connections" in VS, for instance?
|
|
|
|
|
I was doing this
dt.Rows.Add(ds.Tables[0].Rows[1]);
Where dt is one table and ds.Tables[0] is another table. Now the
above statement throws up an error stating that "the row already
belongs to one table"
if i define an ArrayList
ArrayList al = new ArrayList()
and do
al.Add(ds.Tables[0].Rows[1])
this one works. Does any one know why the first one doesn't work
Probably the round about way is creating a new datarow and getting
the values from the ds.Tables[0] for that row and rebuilding the new row
for the dt table. But dont you guys think it make sense to directly copy the whole row from one datatable to another.
How do i do it.
Thanks
kal
|
|
|
|