[Info-vax] Cross-language OO compatibility, was: Re: September 6, 2016 - new Roadmap and State of the Port updates now on VSI website
Simon Clubley
clubley at remove_me.eisner.decus.org-Earth.UFP
Sat Sep 10 10:20:29 EDT 2016
On 2016-09-09, Stephen Hoffman <seaohveh at hoffmanlabs.invalid> wrote:
> On 2016-09-09 14:14:58 +0000, John Reagan said:
>
>> As Steve said, there are abstractions above the calls to LIB$GET_VM and
>> LIB$MALLOC. You wouldn't expect to do a NEW in Pascal, pass the
>> pointer to a C routine and do a free(), would you?
>
> I work in another development environment where passing around objects
> in that fashion is the norm. Allocated by a system or library call or
> a user routine, and passed around or copied or retained as needed, and
> eventually released by user code. This is a central part of the
> difference between non-OO and non-GC and OO and GC environments, and
> it's certainly good fodder for the VSI advanced development team.
>
And in some languages it's not always that simple.
A pure C++ example: create a struct which contains a mixture of
primitive variables (ie: ints/floats) and some std::string variables
(or other objects which require initialisation). Note I don't mean
place pointers to std::string variables within the struct but to place
the actual variables themselves within it.
Now use malloc() to allocate memory for the struct and then try to use
those std::string objects in your newly allocated memory (good luck).
Even if you managed to manually initialise those objects in your
malloc() allocated memory, then doing a free() would cause the struct
memory to be simply released without any destructors firing.
IOW, John is absolutely right about this one and there's a reason why
new and delete exist in C++.
Simon.
--
Simon Clubley, clubley at remove_me.eisner.decus.org-Earth.UFP
Microsoft: Bringing you 1980s technology to a 21st century world
More information about the Info-vax
mailing list