Advertisement
Guest User

Untitled

a guest
Jul 7th, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.62 KB | None | 0 0
  1. Content CreatedOn
  2. It says here that "... the number-of-calls figures are derived by counting, not sampling. They are completely accurate...". Yet I find my call graph giving me 5345859132+784984078 as call stats to my most called function, where the first number is supposed to be direct calls, and the second recursive calls (which are all from itself). Since this implied I had a bug, I put in long (64bit) counters into the code and did the same run again. My counts : 5345859132 direct, and 78094395406 self-recursive calls. There's a lot of digits there, so I'll point out the recursive calls I measure are 78bn, versus 784m from gprof : a factor of 100 different. Both runs were single threaded and unoptimised code, one compiled -g and the other -pg. 2012-06-26 10:48:34.000
  3. System databases with ID 5 and 6 will be ReportServer and ReportServerTempDB if you have SQL Server Reporting Services installed. 2012-06-29 17:57:40.000
  4. There are special databases for XML like MarkLogic and Berkeley XMLDB. They can index xml-docs and one can query them with XQuery. I expect JSON databases, maybe they already exist. Did some googling but couldn't find one. 2012-07-01 18:19:03.000
  5. That is the typical workaround Thanks for the contribution. Resharper is smart enough to recognize this pattern and bring it to your attention too, which is nice. I haven't been bit by this pattern in a while, but since it is, in Eric Lippert's words, "the single most common incorrect bug report we get," I was curious to know the why more than the how to avoid it. 2012-07-02 10:46:29.000
  6. Yes, MemberwiseClone makes a shallow copy, but the opposite of MemberwiseClone isn't Clone; it would be, perhaps, DeepClone, which doesn't exist. When you use an object through its ICloneable interface, you can't know which kind of cloning the underlying object performs. (And XML comments won't make it clear, because you'll get the interface comments rather than the ones on the object's Clone method.) 2012-07-02 20:08:44.000
  7. The rule for resolving which type is implied, can be loosely stated like this: First search the inner-most "scope" for a match, if nothing is found there go out one level to the next scope and search there, and so on, until a match is found. If at some level more than one match is found, if one of the types are from the current assembly, pick that one and issue a compiler warning. Otherwise, give up (compile-time error). 2012-07-18 13:51:15.000
  8. Schwartz, if I were talking about the way things had to work according to the standard, you'd be correct. But that's not what I'm talking about - I'm talking about actual observed behavior with a very popular compiler, and extrapolating based on my knowledge of typical compilers and CPU architectures to what will probably happen. If you believe references to be superior to pointers because they're safer and don't consider that references can be bad, you'll be stumped by a simple problem someday just as I was. 2012-07-24 05:15:48.000
  9. I won't debate the "poor man" part :-) It's true that statistical measurement precision requires many samples, but there are two conflicting goals - measurement and problem location. I'm focussing on the latter, for which you need precision of location, not precision of measure. So for example, there can be, mid-stack, a single function call A(); that accounts for 50% of time, but it can be in another large function B, along with many other calls to A() that are not costly. Precise summaries of function times can be a clue, but every other stack sample will pinpoint the problem. 2012-07-28 10:18:34.000
  10. Well, a join is used to make a new "pseudo table", upon which the filter is applied. So, you have the filter criteria and the join criteria. The join criteria is used to build this "pseudo table" and then the filter is applied against that. Now, when interpreting the join, it's again the same issue as the filter -- brute force comparisons and index reads to build the subset for the "pseudo table". 2012-07-29 23:14:38.000
  11. Placing the using-alias directive outside of the namespace is a bad practice because it can lead to confusion in situations such as this, where it is not obvious which version of the type is actually being used. This can potentially lead to a bug which might be difficult to diagnose. 2012-08-11 16:43:03.000
  12. Is there something you can do with foreach loops this way that you couldn't if they were compiled with an inner-scoped variable? or is this just an arbitrary choice that was made before anonymous methods and lambda expressions were available or common, and which hasn't been revised since then? 2012-08-17 09:18:09.000
  13. Abandoning all the perfectly sane and useful Exception .net provides (ArgumentException, InvalidOperationException etc.) for the sake of being able to catch "MyApplicationBaseException" seems to offer a bad cost/benefit relation. Also, it won't help me if I want to catch exceptions thrown by string.Format and other Framework methods. 2012-08-23 16:46:05.000
  14. And of course FxCop barks at you and so you have to also add an attribute to your code that has precisely zip to do with the running program, and is only there to tell FxCop to ignore an issue that in 99.9% of cases it is totally correct in flagging. And, sorry, I might be mistaken, but doesn't that "ignore" attribute end up actually compiled into your app? 2012-09-06 23:06:29.000
  15. Added: It might not be obvious, but the stack sampling technique works equally well in the presence of recursion. The reason is that the time that would be saved by removal of an instruction is approximated by the fraction of samples containing it, regardless of the number of times it may occur within a sample. 2012-09-07 12:02:28.000
  16. Precisely--concise, and you totally bypass the performance penalty of handling the exception, the bad form of intentionally using exceptions to control program flow, and the soft focus of having your conversion logic spread around, a little bit here and a little bit there. 2012-09-10 08:19:31.000
  17. As per the Wikipedia:
  18.  
  19. The class must have a public default constructor (with no arguments). This allows easy instantiation within editing and activation frameworks.
  20.  
  21. The class properties must be accessible using get, set, is (can be used for boolean properties instead of get), and other methods (so-called accessor methods and mutator methods) according to a standard naming convention. This allows easy automated inspection and updating of bean state within frameworks, many of which include custom editors for various types of properties. Setters can have one or more than one argument.
  22.  
  23. The class should be serializable. [This allows applications and frameworks to reliably save, store, and restore the bean's state in a manner independent of the VM and of the platform.]
  24.  
  25. For more information follow this link. 2012-09-13 04:00:42.000
  26. Cutting straight to the chase, this kind of duplicates an earlier answer, but if you really want to perform a common action for several exception types and keep the whole thing neat and tidy within the scope of the one method, why not just use a lambda/closure/inline function do something like the following? I mean, chances are pretty good that you'll end up realizing that you just want to make that closure a separate method that you can utilize all over the place. But then it will be super easy to do that without actually changing the rest of the code structurally. Right? 2012-09-18 04:39:53.000
  27. this does not work very well in a medium to large development team where some level of code consistency is required. And as noted previously, if you don't understand the different layouts you may find edge cases that don't work as you expect. 2012-09-21 02:16:58.000
  28. You may have multiple performance problems of different sizes. If you clean out any one of them, the remaining ones will take a larger percentage, and be easier to spot, on subsequent passes. 2012-10-13 22:49:14.000
  29. I use the following SQL Server Management Objects code to get a list of databases that aren't system databases and aren't snapshots.
  30.  
  31. using Microsoft.SqlServer.Management.Smo;
  32.  
  33. public static string[] GetDatabaseNames( string serverName )
  34. {
  35. var server = new Server( serverName );
  36. return ( from Database database in server.Databases
  37. where !database.IsSystemObject && !database.IsDatabaseSnapshot
  38. select database.Name
  39. ).ToArray();
  40. } 2012-10-14 05:54:40.000
  41. I have created a version of the accepted answer that works with both '[Serializable]' and '[DataContract]'. It has been a while since I wrote it, but if I remember correctly [DataContract] needed a different serializer.
  42.  
  43. Requires System, System.IO, System.Runtime.Serialization, System.Runtime.Serialization.Formatters.Binary, System.Xml; 2012-10-27 17:50:58.000
  44. Java Beans are using for less code and more work approach... Java Beans are used throughout Java EE as a universal contract for runtime discovery and access. For example, JavaServer Pages (JSP) uses Java Beans as data transfer objects between pages or between servlets and JSPs. Java EE's JavaBeans Activation Framework uses Java Beans for integrating support for MIME data types into Java EE. The Java EE Management API uses JavaBeans as the foundation for the instrumentation of resources to be managed in a Java EE environment.
  45.  
  46. About Serialization:
  47.  
  48. In object serialization an object can be represented as a sequence of bytes that includes the object's data as well as information about the object's type and the types of data stored in the object.
  49.  
  50. After a serialized object has been written into a file, it can be read from the file and deserialized that is, the type information and bytes that represent the object and its data can be used to recreate the object in memory. 2012-11-01 02:14:58.000
  51. How fast it is?
  52.  
  53. The solution is faster then reflection, because members information has to be gathered only once, before GetClone<T> is used for the first time for given type T.
  54.  
  55. It's also faster than serialization-based solution when you clone more then couple instances of the same type T. 2012-11-02 21:22:32.000
  56. Like most language features, bit fields can be used correctly or they can be abused. If you need to pack several small values into a single int, bit fields can be very useful. On the other hand, if you start making assumptions about how the bit fields map to the actual containing int, you're just asking for trouble. 2012-11-06 19:28:01.000
  57. Good question. The following are some thoughts in no particular order:
  58.  
  59. Normalization, to at least the second normal form, is essential.
  60.  
  61. Referential integrity is also essential, with proper cascading delete and update considerations.
  62.  
  63. Good and proper use of check constraints. Let the database do as much work as possible.
  64.  
  65. Don't scatter business logic in both the database and middle tier code. Pick one or the other, preferably in middle tier code.
  66.  
  67. Decide on a consistent approach for primary keys and clustered keys.
  68.  
  69. Don't over index. Choose your indexes wisely.
  70.  
  71. Consistent table and column naming. Pick a standard and stick to it.
  72.  
  73. Limit the number of columns in the database that will accept null values.
  74.  
  75. Don't get carried away with triggers. They have their use but can complicate things in a hurry.
  76.  
  77. Be careful with UDFs. They are great but can cause performance problems when you're not aware how often they might get called in a query.
  78.  
  79. Get Celko's book on database design. The man is arrogant but knows his stuff. 2012-11-25 06:24:09.000
  80. Callgrind is a profiler build upon that. Main benefit is that you don't have to run your aplication for hours to get reliable result. Even one second run is sufficient to get rock-solid, reliable results, because Callgrind is a non-probing profiler.
  81.  
  82. Another tool build upon Valgrind is Massif. I use it to profile heap memory usage. It works great. What it does is that it gives you snapshots of memory usage -- detailed information WHAT holds WHAT percentage of memory, and WHO had put it there. Such information is available at different points of time of application run. 2012-11-26 18:01:22.000
  83. It seems you (and/or your company) have a fundamental misunderstanding of what a family tree is supposed to be.
  84.  
  85. Let me clarify, I also work for a company that has (as one of its products) a family tree in its portfolio, and we have been struggling with similar problems. 2012-12-16 13:03:18.000
  86. The best thing to do for cloning objects in c sharp!
  87.  
  88. First and foremost, those are all our options:
  89.  
  90. Manually with ICloneable, which is Shallow and not Type-Safe
  91. MemberwiseClone, which uses ICloneable
  92. Reflection by using Activator.CreateInstance
  93. Serialization, as pointed by johnc's preferred answer
  94. Intermediate Language, which I got no idea how works
  95. Extension Methods, such as this custom clone framework by Havard Straden 2012-12-18 19:59:49.000
  96. The bottom line is that this is a general solution to an entire class of problems. It is, of course, possible and even appropriate to rewrite the equivalent of any of these macros with explicit mask values every time you need one, but why do it? Remember, the macro substitution occurs in the preprocessor and so the generated code will reflect the fact that the values are considered constant by the compiler - i.e. it's just as efficient to use the generalized macros as to "reinvent the wheel" every time you need to do bit manipulation. 2012-12-28 07:18:06.000
  97. Thank you for that link! I just learned one more important reason not to re-throw: throw e; destroys stacktrace and callstack, throw; destroys "only" callstack (rendering crash-dumps useless!) A very good reason to use neither if it can be avoided! 2012-12-28 20:02:57.000
  98. Finding true cycles in a tree can be done in a few ways. The wrong way is to mark every ancestor from a given individual, and when traversing, if the person you're going to step to next is already marked, then cut the link. This will sever potentially accurate relationships. The correct way to do it is to start from each individual, and mark each ancestor with the path to that individual. If the new path contains the current path as a subpath, then it's a cycle, and should be broken. You can store paths as vector<bool> (MFMF, MFFFMF, etc.) which makes the comparison and storage very fast.
  99.  
  100. There are a few other ways to detect cycles, such as sending out two iterators and seeing if they ever collide with the subset test, but I ended up using the local storage method.
  101.  
  102. Also note that you don't need to actually sever the link, you can just change it from a normal link to a 'weak' link, which isn't followed by some of your algorithms. You will also want to take care when choosing which link to mark as weak; sometimes you can figure out where the cycle should be broken by looking at birthdate information, but often you can't figure out anything because so much data is missing. 2013-01-01 06:06:10.000
  103. @worldsayshi - No, it's not required. For example a bean can contain a String; and String is not a bean. (String is immutable, so you cannot create it by calling an empty constructor and a setter.) It seems reasonable that a Serializable object should have Serializable members, unless it somehow serializes them from outside. So no, Java bean members do not need to have any aspect of Java beans. Although it is more simple if they are beans, too. 2013-01-09 09:20:31.000
  104. The code creates an alias to the System.Guid type called Guid, and also creates its own type called Guid with a matching constructor interface. Later, the code creates an instance of the type Guid. To create this instance, the compiler must choose between the two different definitions of Guid. When the using-alias directive is placed outside of the namespace element, the compiler will choose the local definition of Guid defined within the local namespace, and completely ignore the using-alias directive defined outside of the namespace. This, unfortunately, is not obvious when reading the code. 2013-01-23 05:35:18.000
  105. If the two objects are of the same type, it would make more sense to make this a generic method with a single type parameter to enforce that. If they are not the same type, you'll have to handle the possibility that properties with the same name might have incompatible types. For example, S might have a property called "ID" of type int, while T's ID property might be a Guid. 2013-01-25 07:09:16.000
  106. I like using the static initializer "technique" when I have a concrete realization of an abstract class that has defined an initializing constructor but no default constructor but I want my subclass to have a default constructor. 2013-02-07 00:51:48.000
  107. Bit fields are bad in so many ways, I could almost write a book about it. In fact I almost had to do that for a bit field program that needed MISRA-C compliance. MISRA-C enforces all implementation-defined behavior to be documented, so I ended up writing quite an essay about everything that can go wrong in bit fields. Bit order, endianess, padding bits, padding bytes, various other alignment issues, implicit and explicit type conversions to and from a bit field, UB if int isn't used and so on. Instead, use bitwise-operators for less bugs and portable code. Bit fields are completely redundant. 2013-02-14 23:26:59.000
  108. We have modeled our family tree to what happens in the real world: Events (for example, births, weddings, engagement, unions, deaths, adoptions, etc.). We do not put any restrictions on these, except for logically impossible ones (for example, one can't be one's own parent, relations need two individuals, etc...)
  109.  
  110. The lack of validations gives us a more "real world", simpler and more flexible solution.
  111.  
  112. As for this specific case, I would suggest removing the assertions as they do not hold universally.
  113.  
  114. For displaying issues (that will arise) I would suggest drawing the same node as many times as needed, hinting at the duplication by lighting up all the copies on selecting one of them. 2013-02-17 23:09:27.000
  115. The problem with this approach is that it is not type-safe at all (and if you are using Java, you want type safety). You can put any kind of objects as keys and values. It only really works for a Map<Object, Object> (though one could use an analogous approach with an String[][] for Map<String,String> and similar for other Map<T,T>. It doesn't work for Maps where the key-type is different from the value type. 2013-03-05 15:58:54.000
  116. Aye I didn't fully read the thread but bought in when the MVPs said it was right. A guy disproves it, explains it and shows his code further down... "The IL that the C# compiler generates is the same in either case. In fact the C# compiler generates precisely nothing corresponding to each using directive. Using directives are purely a C#ism, and they have no meaning to .NET itself. (Not true for using statements but those are something quite different.) 2013-03-08 05:26:41.000
  117. @Anthony: Yes. The compiler team refers to this as hoisting rather than lifting, since "lifting" already has a meaning for nullable arithmetic. But stop thinking about the stack altogether. The stack is an implementation detail subject to change. The compiler uses the stack -- or registers -- when doing so is convenient and correct. In this case it is neither, so the stack isn't used. 2013-03-08 14:32:22.000
  118. +1 on your comment above. But aren't you looking to abandon all the perfectly sane and useful exception handling syntax provided to elegantly catch multiple exceptions? That you want to execute an identical body of code as a result of differing conditions is pretty much the use-case for a method call. But we don't try to group-together (in potentially obscure if/then blocks) all the other pre-cursors to a particular method call in other parts of our program, so should we do it here? Not arguin', just philosophisin' (in fact I came here as I had the same question as you)! ;-) 2013-03-17 13:00:37.000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement