Old FPC ObjectModel

Hello,

I recently realized that Delphi as well FPC has Support for the stack-allocated-object allocation, means the “object” can do everything a class can BUT: it is allocated on the stack.

What do you think about this concept and is it introduceable for oxygene?

–Shpend :slight_smile:

what does this give you that a record doesn’t?

You dont have polymorphism with records. :confused:

Because I read relatively often from developers that they want a custom-data-type with valuelogic, allocated on the stack and support every-OOP-Feature a class does.

Oddly, in over 12 years i’ve not seen this requested once.

in any case, not going to happen. Borland Pascal’s old “object” model was deprecated and outdated even i Delphi 1.0 in 1994 — we’re not gonna put effort into bringing it back.

—marc

FWIW - I think the call is often not for every OOP feature, but most often for inheritance/polymorphism.

The use cases are relatively few and far between. When you run into the occasional need you do find yourself willing to give up a limb in exchange for it, but the pain of having to live with a reference type around a property bag is quickly forgotten. Until the next time.

And so on. :shrug:

The most recent needs for it I ran into were for “rational number representation” (i.e. fractions) and “currency value with currency type”. Datetime with timezone is another, though this can usually be worked around by normalising all datetimes to UTC - the only problem arising if you need to carry the original timezone around with a datetime for purposes other than normalising comparisons with other datetimes.

i.e. in all cases these are “value types with twiddly bits”.

It’s one of those things, problem is that records are relatively inefficient when they become larger, especially considering we don’t have c++'s “const” and & type modifiers.

We do have an issue to look into escape analysis (some time in the future), where it turns a class into a record if it never escapes the stack, which covers at least part of the use case for this.

@ck
What exactly do you mean by it?

Do you think also, that the fpc-object-model is important to have or do I missunderstand you totally :smiley: ?

what I mean is that at some point in the future we’re going to look at an optimization phase that might place classes on the stack when the compiler can prove they don’t escape the function.

I don’t think fpc’s object model is something we currently want or need.

3 Likes

That would be ofc very nice but I have still another idea:

Why not, like in C++, to be able to place a class via pointer to heap and without a pointer on the stack?

You have the total possibility from a class in the stack and heap.

That would be a great possibility, isnt it?

The Thing is, some models of C++ are very good, I dont actually like the language at all, but some of ist Features makes it very flexible, like those, IMO

Because it would completely change and thus break the language? And the use cases for it seem to be limited.

1 Like