Sunday, March 20, 2011

Converting a .NET object to (byte*)

Is there a way to cast a System.Object to byte*?

From stackoverflow
  • According to Jon Skeet, it is possible through just casting it to a byte array.

    Michal Franc : I need cast to unsafe pointer. I ve made a workaround. Passing int through function. I can easily convert byte* to int and int to byte*. But still the question is here.
    streetparade : @steven i postet jon skets code above ;-)
    monksy : After I posted the source.
  • Just use:

    byte[] b = (byte[]) myobj;
    
  • How about something like...

    BinaryFormatter bf = new BinaryFormatter();
    System.IO.MemoryStream ms = new System.IO.MemoryStream(1024);
    
    Object1 blah = new Object1("Hello");
    
    bf.Serialize(ms, blah);
    byte[] bytes = ms.GetBuffer();
    
  • OK, I found the solution:

    (byte*)(int)someObject
    
    Jan : What if someObject is larger than an int?
    Michal Franc : In my scenario it wont happen. But yes you are right.
    Hans Passant : Doesn't work in 64-bit mode. A pointer is larger than an int.

Materialized View fast refresh taking a long time

I have a large table that is replicated from Oracle 10.2.0.4 to and Oracle 9i database using MView replication over the network. The master table is about 50GB, 160M rows and there are about 2 - 3M new or updates rows per day.

The master table has a materialized view log created using rowid.

The full refresh of the view works and takes about 5 hours, which we can live with.

However the fast refresh is struggling to keep up. Oracle seems to require two queries against the mlog and master table to do the refresh, the first looks like this:

SELECT          /*+ */
   DISTINCT "A1"."M_ROW$$"
       FROM "GENEVA_ADMIN"."MLOG$_BILLSUMMARY" "A1"
      WHERE "A1"."M_ROW$$" <> ALL (SELECT "A2".ROWID
                                     FROM "GENEVA_ADMIN"."BILLSUMMARY" "A2"
                                    WHERE "A2".ROWID = "A1"."M_ROW$$")
        AND "A1"."SNAPTIME$$" > :1
        AND "A1"."DMLTYPE$$" <> 'I'

The current plan is:

---------------------------------------------------------------
| Id  | Operation                     | Name                  |
---------------------------------------------------------------
|   0 | SELECT STATEMENT              |                       |
|   1 |  HASH UNIQUE                  |                       |
|   2 |   FILTER                      |                       |
|   3 |    TABLE ACCESS BY INDEX ROWID| MLOG$_BILLSUMMARY     |
|   4 |     INDEX RANGE SCAN          | MLOG$_BILLSUMMARY_AK1 |
|   5 |    TABLE ACCESS BY USER ROWID | BILLSUMMARY           |

When there are 3M rows changed, this query literally runs forever - its basically useless. However, if I rewrite it slightly and tell it to full scan the master table and mlog table, it completes in 20 minutes.

The problem is that the above query is coming out of the inners of Oracle and I cannot change it. The problem is really the FILTER operation on line 2 - if I could get it to full scan both tables and hash join / anti-join, I am confident I can get it to complete quick enough, but no receipe of hints I offer will get this query to stop using the FILTER operation - maybe its not even valid. I can use hints to get it to full scan both the tables, but the FILTER operation remains, and I understand it execute long 5 for each row returned by line 3, which will be 2- 3M rows.

Has anyone got any ideas on how to trick this query into the plan I want without changing the actual query, or better, any ways of getting replication to take a more sensible plan for my tablesizes?

Thanks,

Stephen.

From stackoverflow
  • Hi Stephen,

    As you wrote the queries are part of an internal Oracle mechanism so your tuning options are limited. The fast-refresh algorithm seems to behave differently in the more recent versions, check Alberto Dell’Era’s analysis.

    You could also look into SQL profiles (10g feature). With the package DBMS_SQLTUNE this should allow you to tune individual SQL statements.

    Stephen ODonnell : Good information in Alberto's posts - I had worked a good bit of that out myself, but its good to see someone else say the same things. I am thinking of 'rolling my own' fast refresh on this - its only 3 or 4 queries at the end of the day.
    Vincent Malgrat : @Stephen: good luck with that, I think it may be your best option too. Share it here when you have done it :>
  • How do the estimated cardinalities look for the refresh query in comparison to the actual cardinalities? Maybe the MLOG$ table statistics are incorrect.

    It might be better to have no statistics on the table and lock them in order to invoke dynamic sampling, which ought to give a reasonable estimation based on the multiple predicates in the query.

    Stephen ODonnell : We have tried no stats, accurate stats and 'faking the stats' by setting the number of rows and blocks in the MLog table way higher that it should be and the plan doesn't change. Extracting the query, I can change the access paths with hints (or stored outlines) but getting rid of that filter step in the plan doesn't seem to be possible probably due to the <> ALL ... part of the query. I was hoping an anti-join or something would work, but those hints are being ignored.
    David Aldridge : When you tried no stats did you verify that dynamic sampling was being invoked (the trace file would show the dynamic sampling query)? What is the optimiser mode? The RBO would be disinclined to full scan if it could avoid it, of course.

Is there any way on how we could detect and get the attributes (which do not have properties) from a user control tag?

<uc1:UsercontrolTest ID="UsercontrolTest" runat="server" Hello="World"/>

You see, Hello is not a property of UsercontrolTest class, but we need to detect and get that attribute. Are we allowed to do that? Thanks.

From stackoverflow
  • Does the following not work?

    UsercontrolTest.Attributes("Hello")
    

    EDIT:

    UserControl.Attributes : Gets a collection of all attribute name and value pairs declared in the user control tag within the .aspx file.

    Jronny : What we need actually is to *detect* what the attributes used in the tag are... Guess I should edit my question. =)
    ChristopheD : I've edited my answer
    Jronny : That is okay when we have the idea what the attributes are set on the tag. In my case, I know that the attribute is Hello, but what if another attribute (which I do not have any idea on what it is) is added? Thanks for the reply, by the way.
    marc_s : IF you don't know what the attribute is called, just inspect the list in `UserControl.Attributes` - it will contain the name of the attribute and the value it's set to
    Jronny : That's my problem actually. How can we inspect the UserControl.Attributes? The AttributeCollection does not have a List or Dictionary properties.

Wednesday, March 16, 2011

What do Colleges now teach in BS in Computer Science?

20 years I was taught languages (Pascal, Basic, LISP), data structures and algorithms, and math classes. I would like to know what is being taught in the last 10 years?

Are there courses on process and life cycle?

Are there Microsoft .Net and Java specific courses?

Are there business application development and enterprise computing courses?

From stackoverflow
  • I finished my degree 2 years ago. We covered languages (Java, C, Eiffel, Lisp, Prolog), data structures, interface design, statistics, and math. There were theory courses as well (OS basics, machine language). You had some choice courses, so you could take some business courses, but it wasn't mandatory. Nor was the interface design course, but it did cover building business applications, and was a fairly popular choice.

    York University Computer Science Department

  • 15-10 years ago, in addition to the topics you mentioned, I took courses in operating systems, networks, computer graphics, AI, theory of computation, and human-computer interaction. Java just came about at the end of my undergrad years, and .Net did not exist yet. There were no business application development courses of any kind.

  • You could just pick your favorite university's web site and look at their degree plans and course catalog.

    Here's my school. And their course catalog.

  • Lots of math, Data Structures, Digital Systems, Computer Architecture, Analysis of Algorithms, general programming language concepts, OS, Software Engineering, and some other specialties as electives. These include things like AI, image processing, graphics, etc.

  • My school had required courses on general computer science topics, computer organization (i.e., how processors work and interact with memory, etc.), programming language theory, algorithms and data structures, and basic operating systems design. Electives included compiler optimization, graph theory, graphics, networks, and security, among others. Required math courses included calculus, discrete math, and probability and statistics.

    We were taught to program in Java on Red Hat Linux, although some courses utilized C and C++ as well; the programming language theory course used Haskell.

    We had only very basic instruction on the software development process and life cycle. But this is a good thing -- that's software engineering stuff, and computer science is not software engineering. We barely had time to scratch the surface of CS, so SE would've just been too time-consuming. (That said, seniors did take a course that involved the development of a software project using extreme/agile programming techniques.)

    Adam Jaskiewicz : I had pretty much the same courseload and languages, save that the Programming Languages course used Scheme rather than Haskell, and "computer organization" was called "computer architecture" and involved writing some basic stuff in MIPS assembly and making a simple 16 bit CPU in a logic simulator.
    mipadi : Yeah, the computer organization course I was also based on MIPS32, and we did similar stuff.
  • I finished my degree alittle more then a year ago. While obviously I can't speak for all programs. The curriculum I had was very similar to yours.

    C++ for most courses including data structures in C++. AI in prolog and python. I had an operating systems course where we used Java, my database course also used Java and JDBC. However, most .net and java specifics I have learned outside of school. My program really focused on CS theory and mathematics.

  • Obviously I can't speak for everyone, but this is from my own experience. I graduated in May 2007 with a BS in Computer Science.

    Several languages are still taught. My school focused on one language (Java) to teach to new students, but you learned more languages as you advanced. One course in particular was a survey of programming languages and different paradigms (OO, functional, and procedural languages are taught).

    There was a Software Engineering course that touched on processes. Lifecycle is taught from the beginning, since you can't get far without it.

    There were business application development courses that used VB.NET as a platform. There were also a few enterprise computing courses that used J2EE.

    There were also courses in

    • Algorithms and Data Structures
    • Operating Systems
    • Client-Server Programming
    • Network Administration
    • Database Design
  • Purdue University, taught C,C++,Java as primary languages and exposed us Scheme, Smalltalk, Ada, and Prolog.

    We also got to choose our own languages for certain project and classes, I usually would choose python or ruby.

    Also, learning and using Linux was mandatory.

    The classes offered were fairly standard: Data Structures, Networking, Artificial Intelligence, Database, Algorithms, Web Application Development, User Interface Design, Operating Systems, Compiler Construction, and Language design.

  • A lot will depend on what country you're in, and what school you go to.

    Certainly the basics are taught everywhere that I know of:

    • introductory programming
    • algorithm analysis
    • data structures
    • large project class
    • discrete math
    • programming languages

    Beyond that, it's largely up to the institution as to how math-/theory-/business-/practical-heavy they want to be. And whether it's a BS or BA.

  • http://www.gmu.edu/catalog/courses/cs.html

  • Rather than just say it, I'll let my school's CS and SE departments speak for themselves:

  • Many colleges and universities now follow the IEEE/ACM Model curriculum:

    http://www.acm.org/education/curricula-recommendations

    Cheers,

    -Richard

  • U of Idaho CS degree, Fall 08

Best free tool to build an exe from Java code?

I've used JSmoothGen in the past, but recently we've seen a number of machines that refuse to run the .exes that it generates. It also seems not to be actively maintained so heavily any more.

Are there any alternatives that are more actively maintained and more reliable?

From stackoverflow
  • The gnu compiler gcj

    jsight : I'm looking for more of a wrapper than a full to .exe compiler. I already know there isn't one of those that is fully compatible (though GCJ is much better than it used to be).
  • I use Launch4J which supports Windows, Mac and Linux. I suggest forgoing the somewhat flaky GUI tool and just writing the (short, readable) config file yourself.

    jsight : Perfect... thanks!
  • I found this article to be very informative http://www.excelsior-usa.com/articles/java-to-exe.html.

    Someone already mentioned Launch4j, however, I found Jsmooth to be alittle better. They are both very similar, but I would mess with both to see which you prefer.

    EDIT: Sorry, I somehow skimmed over your mention of Jsmooth in your question. If Jsmooth isn't working for you, then I would go for Launch4j. I still recommend that article.

  • This question is a duplicate of How can I convert my java program to an .exe file? in my eyes.

    PhiLho : Well, there is "best" and "free" added in the title... But it is nice to link to another resource.
  • It is also not entirely necessary to make an .exe. On Windows, at least, .jar files are executable so long as there is a Java runtime installed and the .jar extension has been set up on the machine.

    [NOTE: I just discovered that something that has broken the file association, which had previously worked for me. It now only works when I am administrator, and the JAR icon even disappears otherwise. I assume that some recent install has messed with that and the candidates are (1) OpenOffice.org 3.0, (2) WinRAR, or (3) a Java update download. However, the following all work when the association is made to work.]

    The "program" Clicker.jar runs as a Java application when (1) I double-click on it in a Windows Explorer window, (2) When I create a console shell where I am in the same directory and I perform the command ">Clicker.jar" (3) when I send a shortcut to my desktop and double-click on it, and (4) when I put the full path in the Windows XP Run ... box.

    I don't know that these will be found in a PATH search, and I normally wouldn't arrange that anyhow.

  • http://sourceforge.net/projects/javaround

    HTH

Is JSON validation a best practice?

Is it a best practice to validate JSON?

With both a JSON schema proposal and a JavaScript implementation of a JSON Schema validator, this practice would seem relatively frictionless to implement. So, is it a no-brainer that should be part of any robust application? Or do you employ other preferred strategies to handle bad JSON?

From stackoverflow
  • On the server, validation of data coming from outside is a must.

    In the browser, it is redundant from a security POV, if you can vouch that the JSON is generated by server code you control and that any data it depends on has been validated on the server. Even so it can still be useful for debugging.

    happyappa : How are you validating on the server side? I'm kicking my JSON out from PL/SQL, sending it back to a receiving DOJO component. I could see by the JSON references above how to do the validation on the client side...but the server side isn't as clear.
    moonshadow : I mean validate on the server data received from the outside world. If you're bothering to marshall it as JSON in that direction. I'm thinking here of security; for debugging data flowing the other way, validation in the client is good enough. Unhelpfully, I roll my own validation code, I'm afraid.
  • My 2c on this is that:

    (a) Yes, obviously incoming data should be validated, but

    (b) The best place to do this is NOT with Json data as is, but with actual business logic objects, iff data binding is used. JSON validation makes only sense if you handle "raw" JSON, but most services (at least in Java) use data binding first and then operate on biz logic objects, not on data format (which often is almost an implementation detail)

  • I would recommend inclusion of json validation as part of a service perimeter solution. This pattern is described at http://bit.ly/5sSzen

In C#, is accessing the current object's properties through this.XYZ considered poor style compared to just XYZ

Is it a simple case of just never using the this.XYZ construct?

From stackoverflow
  • It's only considered poor style if it violates your style guidelines. Sometimes using this is necessary to qualify a member variable over a local variable:

    public MyType(int arg)
    {
        this.arg = arg;
    }
    

    This problem can also be mitigated with style guidelines. For example, prefix members with "_":

    public MyType(int arg)
    {
        _arg = arg;
    }
    

    HTH, Kent

  • I wouldn't say it's poor style - but it's not particularly idiomatic.

    My almost sole use of this.foo is when copying parameters into fields:

    public Person (string name, string occupation)
    {
       this.name = name;
       this.occupation = occupation;
    }
    
    Will : You don't preface your fields with underscores?
    Jon Skeet : Nope. I never have in my personal code. I've worked at places which do, and I've worked at places which don't. I don't care much any more. What scares me is that I just subconsciously used "brace at end of line" which is the Google style rather than my personal style. Editing...
    Charles Bretana : in general, (except for in initializers - cctors) I always set the public properties, not the private fields, in constructors... so the ctor parameter is lowerCase, and the property is UpperCase... (no need for this.) Name = name;
    Jon Skeet : Charles: That doesn't work when the field is readonly so the property has no setter...
  • I've never heard of it being a style issue. I used to do it all the time to get intellisense, but then I started using ctrl-j, then I just found myself remembering my object's properties without having to use a crutch.

    Probably because my objects have become less complex as I gain more experience...

  • I always use this. for global variable. This way, I can clearly know that I am using a global variable without having to use prefix like "_".

    Kent Boogaart : Yes, because it's so much easier to prefix with "this." than with "_" ;)
    Daok : well, it's clearer in my opinion. And the Intellisense is there... it's part of the Framework.. so why not.
    Daok : I have to add that if you do it all the time and not only for parameter passing to global than it's become easy to follow a code because it's always the same. not "sometime" it's used for global and some time not... but it's just my opinion.
    Kent Boogaart : Yep, makes sense. I haven't yet worked on a project that required prefixing with "this." so don't have any experience having to do so on a regular basis. Was just poking fun...
    Daok : No problem, I think it's really just an opinion and they aren't any good answer.
  • The MS tool StyleCop insists on the this.XYZ (or should that be this.Xyz) variant when analysing source code.

    Kent Boogaart : That's just based on its default rules. You can customize the rules to suit your organization or team.