Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
A

Andrew Shapira

@Andrew Shapira
About
Posts
28
Topics
13
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Does Array.Clear use default?
    A Andrew Shapira

    If one has T[] a = new T[](something); ... Array.Clear(a,0,a.Length); does Array.Clear use default(T)? The documentation for .NET 2.0 and 3.0 suggests that it doesn't (!): public static void Clear(Array array, int index, int length) Sets a range of elements in the Array to zero, to false, or to a null reference (Nothing in Visual Basic), depending on the element type. If Array.Clear really does not use default(T), is there some a base class library method that does this: static void f(Array a, int index, int length) { for (int i = 0; i < a.Length; i++) { a[i] = default(T); } } where T is the type of the array? Maybe this would be something in System.Collections.Generic in order to allow the method's implementation to get at T. It's easy enough to make my own method to do this but I'd just as soon not do it if something already exists in the base class library.

    C# csharp database data-structures question

  • Code reuse: compile-time decisions based on attributes of generic types
    A Andrew Shapira

    Is it possible to write code to make compile-time decisions about which code to include, depending on attributes (or the presence of) generic parameters of the class? For example: class HashTable<TKey,optional TValue> { ... struct Slot { public TKey Key; #if present(TValue) public TValue Value; #endif } } When TValue is present, the hash table would behave like a normal hash table; when TValue is not present, the hash table would behave like a set. The difference between a set and a hash table is very minor and it would be error-prone and inelegant to have to duplicate the entire class to get both a set and hash table from code that, with very little modification, could support both. Something like this might be feasible too (the semantics here with SpecialTValue are problematic; this example is just to illustrate the idea): class HTBase<TKey,TValue> { ... struct Slot { public TKey Key; #if (TValue is SpecialTValue) public TValue Value; #endif } } class HashTable<TKey,TValue> : HTBase<TKey,TValue> class Set<TKey> : HTBase<TKey,SpecialTValue>

    C# data-structures cryptography help tutorial question

  • how to execute ngen output .ni.exe file
    A Andrew Shapira

    I tried that before posting - I don't think it works. The md5 sum of helloworld.exe is unchanged by running "ngen install helloworld.exe".

    .NET (Core and Framework) c++ performance help tutorial question

  • how to execute ngen output .ni.exe file
    A Andrew Shapira

    I am doing performance measurements and would like to use a native executable to avoid having JITs occur during performance timing. How does one execute an ngen-generated executable? There are blogs and MS documentation everywhere that talk about how to use ngen, but I have not found a single place that says how to execute an ngen-executable! :mad: Here is what I tried. Compile: % csc helloworld.cs Then install in the global assembly cache: % ngen install helloworld.exe Then go to the assembly cache and try to execute: % cd c:\windows\assembly\helloworld\[hex string] % ./helloworld.ni.exe This gives the error message: c:\windows\assembly\helloworld\[hex string\helloworld.ni.exe is not a valid WIN32 application.

    .NET (Core and Framework) c++ performance help tutorial question

  • GC-Like Slowdown
    A Andrew Shapira

    Thanks. I think I know what the slowdown is due to - it is probably due to JITting. Now, if I knew how to force the compiler to JIT everything without having to do it in an ad-hoc way like running the benchmark twice.. -- modified at 17:34 Tuesday 5th December, 2006

    C# csharp data-structures cryptography json performance

  • GC-Like Slowdown
    A Andrew Shapira

    The class does small to medium size allocations, generally 32-1000 bytes at a time. The class implementation does a bit of custom memory management in the sense that it maintains a pool of objects for one type of commonly used object. The class runs completely in managed code and I am not willing to change that - this is a general-purpose library-style implementation of a data structure (with essentially the same interface as ystems.Collection.Generic.Dictionary) that is intended for use within managed or unmanaged programs. The test framework does use the WIN32 API to do timing measurements. That is the only part of the test framework that runs in unmanaged code. The amount of time used during these slowdowns is on the order of .02 seconds. Sorry for not mentioning this explicitly in the original post. This amount of time seems orders of magnitude too large to be accounted for by page faults. What do you think?

    C# csharp data-structures cryptography json performance

  • GC-Like Slowdown
    A Andrew Shapira

    The slow operations are rare, at most 1 in 10,000 operations, probably less frequent than that. How would I track this down with a profiler? Given the nature of the code it does not seem likely that exceptions are being thrown in its midst. There are some calls to the base class library but these use things like List and do not seem likely to involve exceptions.

    C# csharp data-structures cryptography json performance

  • GC-Like Slowdown
    A Andrew Shapira

    Does the framework perform any non-garbage-collector operations that slow down applications at time scales similar to thsoe of garbage collections? I ask because in my C# code, a certain operation has a measured average case time of a few microseconds, but once in a while one of these operations takes 5000 times longer than the average. This does not appear to be attributable to varying latency in the memory hierarchy or to variations in the code path followed during the operation. Also, I have verified that no garbage collections occur during these long operations by verifying that GC.CollectionCount did not change during the operation. My timing measurements measure real time, so a factor of 5000 slowdown could easily be due to the operating system, but I thought I would ask here to see if there are any other operations going on in the framework too. (I am working on a hash table implementation for a real time system; I am interested in the worst-case times for add, remove, and retrieve operations.) By the way.. Is there a convenient way to time a block of code without using real time measurements such as with WIN32 API calls to QueryPerformanceCounter and the like? It would be especially nice if the data were accessible from within the program so that the program could report the data and compute auxiliary statistics, instead of having to rely on extra steps that are usually required when using a profiler.

    C# csharp data-structures cryptography json performance

  • RichTextBox Scroll Bar Color
    A Andrew Shapira

    How can one change the color of a scroll bar that's present in a RichTextBox instance?

    .NET (Core and Framework) question

  • Compiler Optimizations
    A Andrew Shapira

    Where is a discussion of the current and future optimizations that the C# compilers do? When I see things like the following I start to question my faith in csc being good at optimizing. (The same kind of thing shows up in cordbg when looking at the JIT code for a similar example.) % cat y.cs using System; class A { bool On { get { return true; } } public void Print() { if (On) { Console.WriteLine("On"); } } } class ConditionalTest { static void Main() { A a = new A(); a.Print(); } } % csc /optimize+ y.cs Microsoft (R) Visual C# .NET Compiler version 7.10.3052.4 for Microsoft (R) .NET Framework version 1.1.4322 Copyright (C) Microsoft Corporation 2001-2002. All rights reserved. % ildasm y.exe .method public hidebysig instance void Print() cil managed { // Code size 19 (0x13) .maxstack 2 IL_0000: ldarg.0 IL_0001: call instance bool A::get_On() IL_0006: brfalse.s IL_0012 IL_0008: ldstr "On" IL_000d: call void [mscorlib]System.Console::WriteLine(string) IL_0012: ret } // end of method A::Print % At least the compiler eliminates the "if" test when "On" is replaced with "true" in the test.

    C# csharp dotnet question tutorial discussion

  • Low Pause-Time Garbage Collector
    A Andrew Shapira

    What are the prospects for a low pause-time garbage collector being added to .NET? (I have a server that is written in .NET, and low latency is important for this server. The server can tolerate many garbage collections, but each garbage collection must be quick. Latencies as long as about 1/3 of a second would be OK; longer is problematic. A garbage collector with pause times of less than .1 second would be great.)

    .NET (Core and Framework) csharp css sysadmin question

  • Assignments and Uses in Multithreaded Environments
    A Andrew Shapira

    Hello -- I am looking for information about the guarantees that .NET makes about assignments completing in a multithreading environment. Specifically, consider the following program that asynchronously finds small factors of integers. The code has been intentionally structured in a slightly peculiar way in order to help make the question clear, and is not necessarily otherwise robust. The question is: what guarantee, if any, does .NET make about the assignment labeled "ASSIGNMENT (1)" completing before the result of the assignment is first referenced in the function "findFactor"? For example, how do we know that the value of d_n isn't in a cache somewhere waiting to be written to memory before findFactor accesses an old value of d_n, or that the compiler hasn't decided to do some instruction reordering so that the completion of the assignment of d_n happens to be delayed until after d_n is referenced in "findFactor"? Similarly, how do we know (or is it even guaranteed) that the assignment labeled "ASSIGNMENT (2)" has completed before the assigned variable is referenced in the Factor property? using System; using System.Threading; /* Asynchronously find the smallest nontrivial factor of a positive integer, using brute force. */ class Factorer { public Factorer() { d_n = 0; d_completed = false; d_worker = null; d_asr = null; } public void BeginWork(int n) { if (n < 2) throw new ApplicationException("n must be an integer greater than 1"); d_completed = false; d_worker = new WorkFunc(findFactor); d_n = n; // ASSIGNMENT (1) d_asr = d_worker.BeginInvoke(null,null); } public bool Completed { get { if ((! d_completed) && d_asr.IsCompleted) { d_worker.EndInvoke(d_asr); d_completed = true; } return d_completed; } } /* Return 0 if n is prime; otherwise return a positive integer that is the smallest factor of n. */ public int Factor { get { if (! Completed) { throw new ApplicationException ("Cannot get result before work is complete."); } return d_factor; } } int d_n; int d_factor; WorkFunc d_worker; IAsyncResult d_asr; bool d_completed; delegate void WorkFunc(); void findFactor() { int n = d_n; if (n == 2) { d_factor = 0; return; } int u = (int) Math.Sqrt(n); for (int i = 2; i <= u; i++) { if ((n % i

    .NET (Core and Framework) question csharp performance help tutorial

  • Managed .NET Embedded Database
    A Andrew Shapira

    Thanks, that is a good possibility. I had looked into in-RAM databases a bit before, and your note inspired me to look at them some more.

    Database csharp database sqlite hardware question

  • In-Memory Databases
    A Andrew Shapira

    Do in-memory database systems such as Prevayler or commercial products have a user-specifiable number N, such that if the system uses more than N bytes of RAM, the system will use virtual memory? That way the database system would use the operating system's virtual memory smarts for managing what goes on disk and what goes in memory, while providing the ability to have a larger database than just what will fit in available RAM.

    Database database performance question

  • Managed .NET Embedded Database
    A Andrew Shapira

    Hi Mike. I am an experienced programmer and am new to databases. Please be nice. Maybe a bit more background about the application will help. I am writing a server application that runs on a dedicated host. I don't need to do complicated SQL queries and I'd be perfectly happy to use a custom API instead of SQL queries. Doing SQL queries may be fine too. The main reasons I have been looking at databases is to get atomic transactions so that the database is always in a consistent state. In my situation recovery is also nice although it's less important than atomic transactions. The ability to access the database from multiple threads would be extremely helpful. Benefits of staying in managed code for this application are type safety, debuggability, and security. Benefits of embedding the database over using a database server are relative ease of deployment and system management. If performance is better using embedding than a database server, that would be another benefit. As you say though, maybe performance will be about the same either way. You mentioned Jet.. Is Jet something that can be used directly from my C# application, or does it have to be used with a higher level package like Access? If it can be used directly, is there somewhere I can read about Jet from a non-propaganda standpoint? I looked around some in Google and found mostly Jet error messages and security bulletins. I have been avoiding Access because my understanding is that Access does not perform well with large databases.

    Database csharp database sqlite hardware question

  • Managed .NET Embedded Database
    A Andrew Shapira

    I'm looking for an embedded .NET database that operates completely in managed code. So far the only one I've found is TurboDB.NET (and I am not sure whether that operates completely in managed code). Are there others?

    Database csharp database sqlite hardware question

  • BinaryWriter/BinaryReader Portability
    A Andrew Shapira

    Thanks Julian. That is just what I wanted to know. Andrew

    C# csharp tutorial question

  • Socket Blocking
    A Andrew Shapira

    Is it possible for calls to Socket.Send() to block? If a socket "s" has s.Available > 0, and one calls s.Receive() with a read length of s.Available, can the call to s.Receive() block? If blocking is possible in the situations described above, is there a way (without using asynchronous I/O) to determine in advance which calls will block, and/or avoid blocking? Andrew

    C# question

  • BinaryWriter/BinaryReader Portability
    A Andrew Shapira

    Ah. No problem.

    C# csharp tutorial question

  • BinaryWriter/BinaryReader Portability
    A Andrew Shapira

    Julian, Is there complete BinaryWriter/BinaryReader compatibility for all Microsoft .NET implementations and for all pairs of machines that Microsoft's .NET runs on? I tried to be explicit about this in the original post -- if the question is still not clear then I will try to make it clearer. I am looking for an explicitly-written answer that's more informative than, "Some BinaryReader objects can read what's written by some BinaryWriter objects." The endianness question is meaningful at present because there are different vendors, e.g., Microsoft and Mono, but even information only about Microsoft-to-Microsoft communication would be helpful. Also, it helps and is even necessary to have some idea of future capabilities. I do not want to release software only to find out in 3 months that a large class of users cannot connect to a server because BinaryWriter and BinaryReader are incompatible in some circumstances, e.g., .NET 2.0 (say) is using a format that is incompatible with .NET 1.0. In fact if this were to happen, then using BinaryWriter/BinaryReader would be painful for many client/server situations because there would be two different classes of users, e.g., many Windows XP users with .NET 1.0 and some other users who are using .NET 2.0. It would become necessary to somehow know in advance which version of the protocol to use, and to be able to use either version within a single assembly (the server). Andrew

    C# csharp tutorial question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups