Search for "Application Profiler" on http://www.gotdotnet.com/community/usersamples/. It'll enable you to see what's going on with your managed heap. There are other similar tools out there; try googling for "managed heap profiler" or similar. Cheers, Julian Program Manager, C# This posting is provided "AS IS" with no warranties, and confers no rights.
Julian Bucknall MSFT
Posts
-
Detect cause of application memory leak -
Array questionArrays are reference types, therefore they're always allocated on the heap. An array of structs is no different -- it'll be on the heap -- however, in this case the memory block on the heap will be a contiguous series of Data structs, one after the other. All that the "new Data()" calls are doing is initializing the various elements of the array. Cheers, Julian Program Manager, C# This posting is provided "AS IS" with no warranties, and confers no rights.
-
IsInRoleHow about:
bool isDishWasher = principal.IsInRole("DishWasher");
Cheers, Julian Program Manager, C# This posting is provided "AS IS" with no warranties, and confers no rights.
-
Encryption/Decryption problemJust a quick reply to your final question (I'm afraid I don't have time at the moment to figure out your code): SSL was designed to protect against man-in-the-middle attacks. Check out the specification of SSL to understand how it works (it involves the exchange of certificates for example). Cheers, Julian Program Manager, C# This posting is provided "AS IS" with no warranties, and confers no rights.
-
Writing hexadecimal to a fileWhat's happening is that, by default, the character is being written out in UTF-8. If you want to just write out the character as if it were a ushort, either cast it to a ushort, or change the encoding for the binary writer. By the way, writing out the ushort 0xABCD to a file will produce 0xCD 0xAB in that order. Cheers, Julian Program Manager, C# This posting is provided "AS IS" with no warranties, and confers no rights.
-
Info for switch statementsThen you have two choices, I suppose: either write out the 30 or so if-elseif lines, or, you take a step back and consider how to refactor the code into something cleaner. The switch statement won't help you, I'm afraid. Cheers, Julian Program Manager, C# This posting is provided "AS IS" with no warranties, and confers no rights.
-
Info for switch statementsNo, I'm afraid you can't do that with C#. The expressions in the case labels must be constant since they're evaluated at compile-time (for speed at run-time). To do what you want to do, you'd use a structure like
if (firstCondition) {
// do stuff
}
else if (secondCondition) {
// do some other stuff
}
else {
// otherwise if all fails do this
}Cheers, Julian Program Manager, C# This posting is provided "AS IS" with no warranties, and confers no rights.
-
BinaryWriter/BinaryReader PortabilityAndrew I'm sorry, I see I wasn't being explicit enough . Any stream written with any existing BinaryWriter can be read by any existing BinaryReader. I can even confirm that fact with Whidbey's BinaryReader and Writer (that is, with .NET Framework 2.0). If it didn't then it's a bug. (So the 3D matrix of 1.0, 1.1, 2.0 frameworks, for the two layers of writers and reader combinations has ticks in every cell). That's the statement about Microsoft's .NET Framework. I know nothing about the Mono project (apart from what it is, of course). I have no idea whether their BinaryReader would always work with a stream createed with BinaryWriter. Similarly I don't know if a stream written by Mono's BinaryWriter would be readable with MS's BinaryReader. However, I would *guess* that the Mono people would have taken endianness into account when they were writing their reader and writer. Now, as to the future (beyond Whidbey): it would make sense for the .NET Framework team to make sure that BinaryReader and BinaryWriter can continue to work as before. Why? Because the ResourceManager uses BinaryReaders and Writers internally. And that would be bad if Visual Studio .NET X (for X>2) couldn't read resource files from existing projects. Also, the format used by BinaryWriter is very, very simple and easily reverse engineered. There's no wierdo enums or class names being put in there or stuff like that. An int is written out as 4 bytes, a double as 8, etc, etc. So, although neither I nor anyone else can really tell you what would happen five years down the road, I wouldn't worry about it. Cheers, Julian Program Manager, C# This posting is provided "AS IS" with no warranties, and confers no rights.
-
BinaryWriter/BinaryReader PortabilityIn answer to your primary question, BinaryReader will read streams created by BinaryWriter correctly. Your question about endianness is meaningless at the present time because .NET only runs on Intel CPUs and hence you don't have to worry about it. Once Microsoft target .NET for other CPUs then, yes, the .NET Frameowrk team will have to worry about how the stream is created and used between different endian CPUs. Cheers, Julian Program Manager, C# This posting is provided "AS IS" with no warranties, and confers no rights.
-
C# switch case styleAh ha! You're reading the "simplified" pages and I'm not surprised that you found ambiguity. Personally I tend to go to the authoritative source, the C# Language Reference. Here you see that a switch statement consists of "switch" followed by an expression in parentheses followed by a switch block a switch block consists of 0 or more switch sections, the whole wrapped in braces a switch section consists of one or more switch labels followed by a list of statements a switch label is either "case" followed by a constant expression followed by colon, or "default" followed by colon. It is the statement list that cannot "fall through." (In fact, it's stated as "the end point of a statement list cannot be reachable," by which it means that you cannot get to the point just after the last statement in the statement list. In other words, the last statement in the list must be a "jump" type statement: break, goto, throw, etc.) Hence, , you can have code that lokos like this: switch (foo) { case 1: case 2: DoSomething(); break; ... } As to the error message, I agree that it could be a little misleading, although it does correctly talk about the last switch label in the (possible) list of labels. Cheers, Julian Program Manager, C# This posting is provided "AS IS" with no warranties, and confers no rights.
-
C# switch case styleI don't understand. Your example of stacking up case labels does compile in C#. Here's a small example:
Random r = new Random(); switch (r.Next(10)) { case 1: Console.WriteLine("It's one"); break; case 2: case 3: case 5: case 7: Console.WriteLine("It's prime"); break; default: Console.WriteLine("It's composite"); break; }
Cheers, Julian Program Manager, C# This posting is provided "AS IS" with no warranties, and confers no rights.
-
Freeze form when it removing and reloading ctlsUse the form's SuspendLayout() and ResumeLayout() methods. Cheers, Julian Program Manager, C# This posting is provided "AS IS" with no warranties, and confers no rights.
-
mp3 calculationsSince the MP3 music format is copyrighted, I would guess that you'd have to purchase a license to the format. That's why you're not getting any hits. Cheers, Julian Program Manager, C# This posting is provided "AS IS" with no warranties, and confers no rights.
-
mp3 calculationsIf I have this kind of question, I use Google and do a little searching. After a couple of minutes I found this on CodeProject itself http://www.codeproject.com/useritems/mp3fileinfo.asp Cheers, Julian Program Manager, C# This posting is provided "AS IS" with no warranties, and confers no rights.
-
XML transferI would suspect that something else is going on since that code should work. It's not as if the operating system treats XML files differently than other files when copying them. I'd play around a little to try and discover what's occurring. Cheers, Julian Program Manager, C# This posting is provided "AS IS" with no warranties, and confers no rights.
-
convert ASCII into charchar MyChar = (char) someIntValue; Cheers, Julian Program Manager, C# This posting is provided "AS IS" with no warranties, and confers no rights.
-
Help: Object reference not set to an instance of an object.Well, I would guess that, since you only create the swStats member when cf.buffCount is true, cf.buffCount is false. Your best bet is to use the debugger to trace through your application. Check that swStats is being created properly, and if it is what else is happening as your app runs. Also, I would define a new class that encapsulates the "create a filestream, create a stream writer" code. You're replicating it several times. Cheers, Julian Program Manager, C# This posting is provided "AS IS" with no warranties, and confers no rights.
-
Using postmessage to interoperate?Unless I'm missing something, just call PerformClick():
private void button1_Click(object sender, System.EventArgs e) {
BusinessRules.PerformClick();
}Cheers, Julian Program Manager, C# This posting is provided "AS IS" with no warranties, and confers no rights.
-
Accessing Over A NETWORK1. Create a share on the target system, and use two FileStreams (one for a file on the local system, the other for a file on the target system) to copy the data over. 2. Use sockets and have a sending application on the source system and a receiving application on the target system. Obviously the target app has to be installed and running before this will work. 3. Use .NET Remoting instead of sockets. Again the target app needs to be installed in the target system. I'm sure that there are other ways, but that'll get you started. Cheers, Julian Program Manager, C# This posting is provided "AS IS" with no warranties, and confers no rights.
-
Holding ArrayLists in an ArrayListYou're just copying references around. When you write
ALSendedList=ALSendedL;
you're merely copying the reference to the array list, you are not copying the array list itself. You need to think about copying the items in the array list instead. Cheers, Julian Program Manager, C# This posting is provided "AS IS" with no warranties, and confers no rights.