Re: memory management



Martin Krischik <krischik@xxxxxxxxxxxxxxxxxxxxx> writes:

> Robert A Duff wrote:
>
> > alex goldman <hello@xxxxxxxx> writes:
> >
> >> As I understood from reading the Ada tutorial for C/C++ programmers,
> >> "access" is essentially like C++ smart pointer,
> >
> > No, Ada access types are just pointers -- no "smarts".
> > To make something like smart pointers, you can use
> > controlled types.
>
> No again - any paricular Ada implementation is free to implement access
> types as they see fit. With GNAT an access may consist of an pointer to the
> data and a pointer to a dope vector:

That's what I call a "fat pointer". Still just a pointer (as opposed to
a smart pointer).

When I say "pointer", I don't mean it has to be implemented as a single
machine address. It could be an offset from some known base address, an
index into an array, or (as you say) a fat pointer -- among other
things.

The same is true of pointers in C and C++ -- an implementation is free
to implement pointers as something other than a machine address. In
fact, if a C compiler wishes to check array bounds, it pretty much *has*
to use fat pointers. I know of one C compiler that did just that. My
point is that "pointer" is not synonymous with "single machine address",
even in C.

By the way, I believe the fat pointers used by GNAT are an option --
there's some way to tell it to use thin pointers for access-to-array.
GNAT uses fat pointers (by default) only when the designated type is an
array, or when the designated type is unknown to the compiler.
Access-to-record, which is far more common, uses thin pointers.
I don't know of any Ada implementation besides GNAT that uses
fat pointers at all.

> http://en.wikipedia.org/wiki/Dope_vector

> Remeber that an Ada compiler may also implement garbage collection.

Yes. That would typically *not* involve smart pointers.

- Bob
.



Relevant Pages

  • Re: API design problem - buffer scatter I/O
    ... (like thin and fat pointers), but that should come at the end. ... FIRST learn about the semantics of access types, ... "Thin pointers grant access to constrained subtypes." ...
    (comp.lang.ada)
  • Re: why the usage of gets() is dangerous.
    ... That's most the point of fat pointers. ... object files with fat-pointer-compiled libraries; ... array, and entirely usable within its scope. ...
    (comp.lang.c)
  • Re: why cant functions return arrays
    ... size the programmer wrote]. ... fact, "impossible", and there are a few compilers that do ... Implementations that provide fat pointers generally run compiled ...
    (comp.lang.c)
  • Re: why the usage of gets() is dangerous.
    ... fat pointers break pointer arithmetic and thus require at ... files with 64-bit libraries, little-endian object files with little- ...
    (comp.lang.c)
  • Re: why the usage of gets() is dangerous.
    ... That's most the point of fat pointers. ... link large memory model object files with large memory model ... The implementation does not have to worry about what happens if you (the programmer) do something the C standard states is undefined, since as you know under those situations anything the implementation does is "correct". ...
    (comp.lang.c)