RFC - Alternatives to gengtype

Jonathan Wakely jwakely.gcc@gmail.com
Fri Nov 23 09:45:00 GMT 2012


On 23/11/2012, Basile Starynkevitch <basile@starynkevitch.net> wrote:
> On Thu, Nov 22, 2012 at 09:29:43PM +0100, Florian Weimer wrote:
>> On 11/18/2012 07:06 PM, NightStrike wrote:
>>
>> >What's wrong with std::shared_ptr?
>>
>> The pointer needs two words, and the per-object overhead for the
>> reference counts etc. is four words, if I'm counting correctly.
>>
>> (Other forms of reference counting have less overhead, of course,
>> but you were asking about std::shared_ptr.)
>
>
> Actually, this observation may favor a real garbage collector. Marking GC as
> simple as ggc+gengtype usually have one (or a few) mark bits, so can consume
> only a few bits (or perhaps a byte in some mark array) per object. Copying
> GC could avoid consuming any more storage per object. Of course useless
> object may stay in memory for a while -until the GC deletes them or reuse
> their memory-

The research shows significantly higher memory usage when relying on
GC in large systems.


> but that observation is also true with traditional C++ "GC"
> techniques like shared_ptr .... An object may be freed later than what
> should be possible.

Only if the code has a bug. Destructors are predictable, immediate and
deterministic.

> And some GC techniques are quite friendly with L1 or L2 caches on the
> processor chip.

And so are some reference counting techniques with intrusive counts,
or using std::make_shared(), so the object and refcount are adjacent
in memory.



More information about the Gcc mailing list