[Date Prev][Date Next][Thread Prev][Thread Next][Author Index][Date Index][Thread Index]

Re: "become" in C++: shepherds and shepherd stubs

Marvelous, and perfectly timed.

> CLASS(Heaper,Tofu) {
>     ...
>     static void *operator new (size_t actualSize, void* space, size_t maximumSize);
>     ...
> };
> /*
> This version of operator new lets an object be constructed in already
> allocated space, after verifying that the space is indeed big enough.
> The maxSize stuff can probably go away, as it would be quite a serious
> bug in a simple mechanism for it to fail, and it is substantial
> trouble to keep track of.
> */

It should be noted that allocated storage carries with it a hidden struct
that contains, among other things, its size.  Therefore, if a runtime check
is desired, the size could be recovered from the pointer (to a non-array
Heaper) by a sizeOf(Heaper *) routine in the allocator.

However, there are only three cases that we are concerned about:

 1) Creating a stub de-novo (by following a pointer), then converting it to
    whatever it represents.

 2) Converting a shepherd to a stub.  (You want to do this because it is what
    allows the sheep and any shepherd stubs held only by this flock to be

 3) Converting a stub that started as a shepherd to the shepherd it represents.

Case 3) is not a problem, because the object has already lived in the memory.

Case 1) requires that stubs be initially created large enough to hold any of
the classes they represent.  This can be guaranteed by an overloaded new for
the stub that gets the size from the stub's Category (or Recipe), and having
said class at initialization time negotiate this size with the equivalent
classes of its constituents.  (The representative's aid negotiating with the
constituents' lobbyists?)

Case 2) requires that all shepherds be created large enough to hold a stub.
Having the stub's size available during the compilation of the shepherd's
operator new requires running stubble over its superclass' files to produce
a .hxx, and places some interesting constraints on file arrangement.  But
a class declaration for a generic stub is easy, and stubs should all be the
same minimum size.  "MAX(sizeof(ShepherdClass),sizeof(GenericStub))" becomes
a single compile-time constant.

> STRP(SomeShepherdClass) someShepherdClass (...)
  ^^^^(I assume this is a typo, not some new pointer type.)

> All clear?

Dianetically.  B-)