RTTI Generation code now available

Over the past couple weeks, I’ve been working on refining and testing my RTTI generation and the scripting system I’ve been building on top of it, which I’ve decided to call RTTI Script.  I think I’m finally starting to get something ready for public consumption.  I set up a Google Code repository this morning for RTTI Script, but so far all it contains is the RTTI generation code.  The actual compiler and script executor still need some work. Continue reading ‘RTTI Generation code now available’ »

Run-time stack information?

Just in case you haven’t listened to it yet, Jim McKeeth over at Delphi.org posted a new podcast last week. He did an interview with Allen Bauer that apparently ran for about two hours, so he split it up into two parts.  The second part isn’t up yet, but there’s a lot of interesting stuff in the first one.  But one of the most interesting things actually came in the comments.

Continue reading ‘Run-time stack information?’ »

Dynamic class creation: moving beyond the theoretical

A few years back, I ran across this post by Hallvard Vassbotn.  (It’s a shame he stopped blogging, because he always had some very interesting stuff about the technical details of how stuff in Delphi works.)  At the bottom was a paragraph that really fascinated me:

On a more technical level it suffices to say that they use custom and extremely compact and fast data structures, tricks and hacks to be able to represent millions and millions of objects within the constraints of a 32-bit Windows system. Throw in the use of Physical Address Extensions, storing per-class information in “virtual” class vars to reduce object instance size, creation of classes and their VMTs dynamically at runtime (!!), pointer packing, multithreading, the list just goes on and on.

Continue reading ‘Dynamic class creation: moving beyond the theoretical’ »

Smaller, cleaner RTTI probably NOT coming

I got an email from Barry Kelly in response to my last post:

I can’t comment on this article as it requires the commenter to be
logged in, and registration is disabled.

There are no plans for a more compact RTTI format. I’d love for there to
be, but the backward compatibility concerns are simply too large.
However, as more code relies on higher-level RTTI constructs, the scope
for freedom there increases incrementally. That’s all I was trying to
say.

– Barry Continue reading ‘Smaller, cleaner RTTI probably NOT coming’ »

Smaller, cleaner RTTI coming?

One of the biggest complaints about the extended RTTI introduced in Delphi 2010 is the way it adds so much to the size of your EXE.  Well, in a recent StackOverflow answer, Barry Kelly hinted that the format of the basic RTTI structures in TypInfo.pas are “more likely to change from version to version now that it has a much higher level abstraction in the Rtti unit.” Continue reading ‘Smaller, cleaner RTTI coming?’ »

XE Update 1: you win some, you lose some

In my first look at Delphi XE, I wrote:

Oh, and apparently certain aspects of the compiler have slowed down.  Most things will compile about the same speed or even a little faster, but for really large projects (millions of lines) with complex interdependencies between units, you’ll notice some slowdown, and it’ll apparently get worse the larger your project is.  I timed it at work, on a project of about 3.5 million lines of code.  It builds in about 2 minutes on D2010, closer to 3 minutes on XE.  Bad, but still a heck of a lot better than the C family could do.  And apparently it has something to do with making Generics work right, so I can tolerate that.  Hopefully they’ll find some way to regain some of that lost speed in updates, though.

Well, I finally got around to installing XE Update 1 at work today, and I timed the build.  2:13. Continue reading ‘XE Update 1: you win some, you lose some’ »

Beware using anonymous methods in loops

Quick, what’s the output of this simple routine?
Continue reading ‘Beware using anonymous methods in loops’ »

TThreadedQueue: interesting, but incomplete

I mentioned the new generic collection TThreadedQueue<T> in my First Look at Delphi XE. I decided to play around with it a little recently.  It’s useful for passing data between one thread that produces output and another that consumes it, keeping the two in step by blocking if the consumer tries to pop from the queue while it’s empty.

The first thread goes through and pushes data into the queue however it wants to.  The second has it easy; all it has to do is loop endlessly until the queue is shut down.  And we all know how to do that:

for value in queue do   process(value);

Except that if you try to do that, the compiler will complain at you.  There’s no enumerator.  For some strange reason, out of all the collections in Generics.Collections, TThreadedQueue<T> alone does not descend from TEnumerable<T>.

Oh well.  It’s not all that hard to add an enumerator to a class that doesn’t have one.  Just use a class helper.

TThreadedQueueEnumerator<T> = class   private     FQueue: TThreadedQueue<T>;     FCurrent: T;     function GetCurrent: T;   public     constructor Create(queue: TThreadedQueue<T>);     property Current: T read GetCurrent;     function MoveNext: Boolean;   end;   TThreadedQueueHelper<T> = class helper for TThreadedQueue<T>   public     function GetEnumerator: TThreadedQueueEnumerator<T>;   end; implementation { TThreadedQueueEnumerator<T> } constructor TThreadedQueueEnumerator<T>.Create(queue: TThreadedQueue<T>); begin   FQueue := queue; end; function TThreadedQueueEnumerator<T>.GetCurrent: T; begin   result:= FCurrent; end; function TThreadedQueueEnumerator<T>.MoveNext: Boolean; begin   result := FQueue.PopItem(FCurrent) = wrSignaled; end; { TThreadedQueueHelper<T> } function TThreadedQueueHelper<T>.GetEnumerator: TThreadedQueueEnumerator<T>; begin   result := TThreadedQueueEnumerator.Create(self); end;

Well, that was easy.  That’s probably the simplest enumerator I’ve ever written, because of the way the queue’s design makes it easy to implement MoveNext.  Except… that doesn’t compile either.  Apparently you can’t put generic type parameters on a class helper, which means that as far as I can tell, you can’t apply a class helper to a generic class at all.

I suppose I could subclass it and add the enumerator that way, but TEnumerableThreadedQueue<T> is a bit of a bulky name, don’t you think?  I have to wonder why the enumerator was left off of this collection, though, especially since the standard enumerator pattern is basically the only reasonable way to use a class like this…

Rule of Law, software, and stray cows

One of the hallmarks of a society that values freedom is the concept of Rule of Law, which basically means that people, even the people in charge, can’t just arbitrarily decide that they don’t like what someone else is doing and act to stop them or punish them for it.  Instead we have laws that explain what’s not allowed, what the punishment for breaking them is, and how they are to be administered.  That administration part is important.  It means that if my neighbor steals something from me, I can’t go and throw him in prison, even if the punishment for it is prison time, because I’m not a law enforcement official.

In fact, we have laws that specifically say that if someone breaks the law, I’m not allowed to punish them for it, even if I was directly harmed by their actions, because I don’t have the authority to enforce the law.  People who attempt to do so are known as vigilantes, and their actions are usually illegal, because vigilante justice is flawed in several fundamental ways.  First, it’s not always easy to know if you’ve got the right guy.  Second, even if you do have the right guy, you don’t know if there are extenuating circumstances for them having done what they did.  (This idea goes a very long way, even to the most serious of crimes.  It’s why there’s a legal distinction between “murder” and “killing in self-defense,” for example.)  And third, even if you have the right guy and you know that they acted maliciously, what you might think of as a proper punishment for the crime may be way over the top, especially if you’re the injured party.  This is why trials for particularly severe and shocking crimes are often held in a different community from where it was committed, to make it possible (or at least easier) to get an impartial jury with no personal stake in the matter.

What does this have to do with software?  Well, if you’ve been following DelphiFeeds lately, you can probably guess. Continue reading ‘Rule of Law, software, and stray cows’ »

Why don’t we have this?

There’s been a lot of talk in the last few years about major language features that Delphi doesn’t have.  Stuff like Unicode and Generics which finally got added in D2009, stuff like 64-bit compilation that’s perenially slated for another year or two out, and so on.  There’s currently a major debate going on (and on and on) in the Delphi forums about the team’s statement that the next release won’t include inline assembly, and the effects that that will or won’t have on library compatibility and future development.

But there are also more minor, simple things that we don’t have, and some of them are a little bit silly. Continue reading ‘Why don’t we have this?’ »