How "heavy" are the respective class hierarchy levels?

From: Raptor (bogus_at_none.com)
Date: 01/31/05


Date: Sun, 30 Jan 2005 19:52:31 -0800

Anyone have a feel for how heavy the respective class hierarchy levels
really are? By "heavy" I mean, of course, how much memory they would
require, comparatively? (Factor in anything else you feel contributes to
"weight" or whatever metaphor you choose.)

Presumably the lightest class level a component writer or programmer would
use is TPersistent. Also presumably, a programmer would seek to use the
simplest class commensurate with programming needs. The levels would be:

TPersistent
    |
    |
TComponent
    |
    |
TControl
    |
    |
TWinControl or TGraphicControl

I've started writing a component whose behavior requires that I know when
the application is loaded. Some deviously evil person named Maarten,
cleverly disguised as a helpful soul, suggested that my code simply send
itself a message, because messages are handled when loading is complete.

Well, TComponents don't have handles, and I can't figure out how to send
and receive a message (within one context) without a handle. Hmmm, TControls
don't have handles, either. Well, I'll just crank out a temporary
TWinControl which will send and receive its own message and be done with it.

But that TWinControl just sits on the curb pouting because it's an orphan
and needs a parent. "Waaah. I want a parent! Gimme a parent. Any parent. I
refuse to do anything until you do."

"C'mon," I respond. "You're sitting here in your own unit and everyone will
laugh at me if I just appoint 'formMain' as your parent. Talk about being a
dependant."

"What about the component class? Maybe I can share its parent."

"Well, maybe. I'll have to promote it to TControl, though, as TComponents
don't have parents."

"So do it already," the brat TWinControl snapped.

The field promotion was unceremonious. Yet TWinControl still refused to
budge.

"Stupid," he snarled. "How can I share TTranslate's parent if he's an orphan
too?"

"You've got a point there," I said, dashing off to the form which tests my
would-be component. "Here..."

procedure TformMain.FormCreate(Sender: TObject);
begin
  aTranslate := TTranslate.Create(self);
  aTranslate.Parent := self;

"and now I'll just..."

constructor TTranslate.Create(aOwner: TComponent);
begin
  inherited Create(aOwner);
  aTheTWinControl:= TTheTWinControl.Create(aOwner);
  aTheTWinControl.Parent := self.Parent;

"ahhh... that should do it."

But it didn't. Junior still needs a mommy. Those with about five minutes
experience will immediately see why.

* Perhaps I could promote TTranslate to a TWinControl so it has a handle,
but this is going to stay in memory. Just how much extra room would that
little fatty take?

* I read that somewhere if this were a full-fledged Registered control, it
would automatically get the form as a parent if t'were plopped on as a
visual component.

"But Doctor, Doctor, it still hurts when I create one dynamically."

"Well, don't do that." Bah-dum-bum.

The End

=====================

What's the price of TWinControl vs. TComponent?

Barring that, any strategies for dynamically obtaining a parent, any parent,
for a transitory invisible control?

Barring that, are Ya-Really-DO-Gotta-Drop-This-On-a-Form controls really
evil? Maybe they're just misunderstood and need love. Heh.

Raptor



Relevant Pages

  • Re: How "heavy" are the respective class hierarchy levels?
    ... a programmer would seek to use the ... > TWinControl which will send and receive its own message and be done with it. ... > and needs a parent. ... > What's the price of TWinControl vs. TComponent? ...
    (alt.comp.lang.borland-delphi)
  • Re: Migrate pages from a ccNUMA node to another
    ... relatively stable memory working sets. ... > on the childs node for the child and parents node for the parent. ... we have beaten on the scheduler quite a bit and the "allocate ... > syscall you seem to be proposing, would be an addition to the ...
    (Linux-Kernel)
  • [patch -mm v2] mm: introduce oom_adj_child
    ... children that do not share memory with the parent. ... That change was necessary to fix an oom killer livelock which would occur ... of a vfork'd child prior to execvebefore the execution actually takes ...
    (Linux-Kernel)
  • Re: [RFC] libcg: design and plans
    ... > i.e. both B and C inherit/share their memory limit from their parent, ... In the create group API, specify the name of the group and the various ... If for example CPU is mounted at /cpu and Memory at /mem ... This kind of sharing has to be handled by the resource ...
    (Linux-Kernel)
  • Re: Superpages on amd64 FreeBSD 7.2-STABLE
    ... or if squid does something particularly horrible to ... Especially because vfork is often called a solution. ... Parent with super page ... parents memory and then starts with a completely new map. ...
    (freebsd-hackers)