青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

Windreamer Is Not a DREAMER
main(){main(puts("Hello,stranger!"));}
發件人: Andrei Alexandrescu (See Website For Email) ?
日期: 2006年3月18日(星期六) 下午12時13分
電子郵件: "Andrei Alexandrescu (See Website For Email)" <SeeWebsiteForEm...@erdani.org>
論壇: comp.lang.c++.moderated

The recent thread "Can GC be beneficial" was quite beneficial :o) - to
me at least. I've reached a number of conclusions that allow me to
better place the conciliation between garbage collection and
deterministic finalization in the language design space - in C++ and in
general.

The following discussion focuses on C++-centric considerations, with
occasional escapes into "the right thing to do if we could break away
with the past.

Basic Tenets, Constraints, and Desiderata
=========================================

Garbage collection is desirable because:

(1) It automates a routine and error-prone task

(2) Reduces client code

(3) Improves type safety

(3) Can improve performance, particularly in multithreaded environments

On the other hand, C++ idioms based on constructors and destructors,
including, but not limited to, scoped resource management, have shown to
be highly useful. The large applicability of such idioms might actually
be the single most important reason for which C++ programmers shy away
from migrating to a garbage-collected C++ environment.

It follows that a set of principled methods that reconcile C++-style
programming based on object lifetime, with garbage collection, would be
highly desirable for fully exploiting garbage collection's advantages
within C++. This article discusses the challenges and to suggests
possible designs to address the challenges.

The constraints include compatibility with existing C++ code and styles
of coding, a preference for type safety at least when it doesn't
adversely incur a performance hit, and the functioning of today's
garbage collection algorithms.

A Causal Design
===============

Claim #1: The lifetime management of objects of a class is a decision of
the class implementer, not of the class user.

In support of this claim we come with the following examples:

a) A class such as complex<double> is oblivious to destruction
timeliness because it does not allocate scarce resource that need timely
release;

b) A class such as string doesn't need to worry about destruction
timeliness within a GC (Garbage Collected) environment;

c) A class such as temporary_file does need to worry about destruction
timeliness because it allocates scarce resources that transcend both the
lifetime of the object (a file handle) and the lifetime of the program
(the file on disk that presumably temporary_file needs to delete after
usage).

In all of these examples, the context in which the objects are used is
largely irrelevant (barring ill-designed types that employ logical
coupling to do entirely different actions depending on their state).
There is, therefore, a strong argument that the implementer of a class
decides entirely what the destruction regime of the class shall be. This
claim will guide design considerations below.

We'll therefore assume a C++ extension that allows a class definition to
include its destruction regime:

?

// ?garbage?collected??
?
class?[collected]?Widget?{...};?
//?deterministically?destroyed??
?
class?[deterministic]?Midget?{...};?


?

These two possible choices could be naturally complemented by the other
allowed storage classes of a class:

?

// ?garbage?collected?or?on?stack??
??
class?[collected,?auto]?Widget?{...};?
//?deterministically?destroyed,?stack,?or?static?storage??
??
class?[deterministic,?auto,?static]?Midget?{...};?

It is illegal, however, that a class specifies both collected and
deterministic regime:

?

// ?illegal??
??
class?[collected,?deterministic]?Wrong?{...};?


?

Claim #2: Collected types cannot define a destruction-time action.

This proposal makes this claim in wake of negative experience with
Java's finalizers.

Claim #3: Collected types can transitively only embed fields of
collected types (or pointers thereof of any depth), and can only derive
from such types.

If a collected type would have a field of a non-collected type, that
type could not be destroyed (as per Claim #2).

If a collected type would have a field of pointer to a non-collected
type, one of two things happens:

a) A dangling pointer access might occur;

b) The resource is kept alive indeterminately and as such cannot be
destroyed (as per claim #2).

If a collected type would have a field of pointer to pointer to (notice
the double indirection) deterministic type, inevitably that pointer's
destination would have to be somehow accessible to the garbage-collected
object. This implies that at the some place in the points-to chain, a
"jump" must exist from the collected realm to the uncollected realm (be
it automatic, static, or deterministic) that would trigger either
post-destruction access, or would prevent the destructor to be called.

Design fork #1: Weak pointers could be supported. A collected type could
hold fields of type weak pointer to non-collected types. The weak
pointers are tracked and are zeroed automatically during destruction of
the resource that they point to. Further dereference attempts accesses
from the collected realm become hard errors.

Claim #4: Deterministic types must track all pointers to their
respective objects (via a precise mechanism such as reference counting
or reference linking).

If deterministic types did allow untracked pointer copying, then
post-destruction access via dangling pointers might occur. The recent
discussion in the thread "Can GC be beneficial" has shown that it is
undesirable to define post-destruction access, and it's best to leave it
as a hard run-time error.

Design branch #2: For type safety reasons, disallow type-erasing
conversions from/to pointers to deterministic types:

?

???
???class?[deterministic]?Widget?{...};?
???Widget?
*?p?=?new?Widget;?
???void?*?p1?=?p;?//?error??
???
p?=?static_cast<Widget?*>(p1);?//?error,?too?

Or: For compatibility reasons, allow type-erasing conversion and incur
the risk of dangling pointer access.

Design branch #3: For purpose of having a type that stands in as a
pointer to any deterministic type (a sort of "deterministic void*"), all
deterministic classes could be thought as (or required to) inherit a
class std::deterministic.

Design branch #3.1: std::deterministic may or may not define virtuals,
and as such confines or not all deterministic classes to have virtuals
(and be suitable for dynamic_cast among other things).

Claim #5: When an object of deterministic type is constructed in
automatic or static storage, its destructor will automatically issue a
hard error if there are any outstanding pointers to it (e.g., the
reference count is greater than one).

If that didn't happen, dangling accesses to expired stack variables
might occur:

?

?class?[deterministic]?Widget?{...};?
?Widget?
*?p;?
int?Fun()?{?
????Widget?w;?
????p?
=?&w;?
????
//?hard?runtime?error?upon?exiting?this?scope?



}
?



?

Discussion of the basic design
==============================

The desiderata set up and the constraints of the current C++ language
created a causal chain that narrowly guided the possible design of an
integrated garbage collection + deterministic destruction in C++:

* The class author decides whether the class is deterministic or garbage
collected

* As a natural extension, the class author can decide whether objects of
that type are allowed to sit on the stack or in static storage. (The
regime of automatic and static storage will be discussed below.)

* Depending on whether a type is deterministic versus collected, the
compiler generates different code for copying pointers to the object.
Basically the compiler automates usage of smart pointers, a
widely-followed semiautomatic discipline in C++.

* The heap is conceptually segregated into two realms. You can hold
unrestricted pointers to objects in the garbage-collected realm, but the
garbage-collected realm cannot hold pointers outside of itself.

* The operations allowed on pointers to deterministic objects are
restricted.

Regime of Automatic Storage
===========================

Claim 6: Pointers to either deterministic or collected objects that are
actually stack allocated should not escape the scope in which their
pointee object exists.

This obvious claim prompts a search in look for an efficient solution to
a class of problems. Here is an example:

?

?class?[auto,?collected]?Widget?{...};?
void?Midgetize(Widget?&?obj)?{?
????obj.Midgetize();?


}
?


void?Foo()?{?
????Widget?giantWidget;?
????Midgetize(giantWidget);?


}
?



?

To make the example above work, Foo is forced to heap-allocate the
Widget object even though the Midgetize function works on it
transitorily and stack allocation would suffice.

To address this problem a pointer/reference modifier, "auto", can be
defined. Its semantics allow only "downward copying": an
pointer/reference to auto can only be copied to lesser scope, never to
object of larger scope. Examples:

?

void?foo()?{?
????Widget?w;?
????Widget?
*auto?p1?=?&w1;?//?fine,?p1?has?lesser?scope?
????{?
??????Widget?
*auto?p2?=?&w;?//?fine?
??????p2?=?p1;?//?fine?
??????p1?=?p2;?//?error!?Escaping?assignment!?
????}
?



}
?



?

Then the example above can be made modularly typesafe and efficient like
this:

?

?class?[auto,?collected]?Widget?{...};?
void?Midgetize(Widget?&auto?obj)?{?
????obj.Midgetize();?


}
?


void?Foo()?{?
????Widget?giantWidget;?
????Midgetize(giantWidget);??
//?fine?


}
?


?

Claim #6: "auto"-modified pointers cannot be initialized or assigned
from heap-allocated deterministic objects.

If "auto"-modified pointers manipulated the reference count, their
efficiency advantage would be lost. If they didn't, a type-unsafe
situation can easily occur.

Does operator delete still exist?
=================================

For collected objects, delete is inoperant, as is for static or
automatic objects. On a heap-allocated deterministic object, delete can
simply check if the reference count is 1, and if so, reassign zero to
the pointer. If the reference count is greater than one, issue a hard ?
error.

Note that this makes delete entirely secure. There is no way to have a
working program that issues a dangling access after delete has been ?
invoked.

Regime of Static Storage
========================

Static storage has the peculiarity that it can easily engender
post-destruction access. This is because the order of module
initialization is not defined, and therefore cross-module dependencies
among objects of static duration are problematic.

This article delays discussion of the regime of static storage.
Hopefully with help from the community, a workable solution to the
cross-module initialization would ensue.

Templates
=========

Claim #7: The collection regime of any type must be accessible during
compilation to templated code.

Here's a simple question: is vector<T> deterministic or collected?

If it were collected, it couldn't hold deterministic types (because at
the end of the day vector<T> must embed a T*). If it were deterministic,
collected types couldn't hold vectors of pointers to collected types,
which would be a major and gratuitous restriction.

So the right answer is: vector<T> has the same regime as T.

?

template?<class?T,?class?A>?
class?[T::collection_regime]?vector?{?//?or?some?other?syntax?
???...?

}
;?


?

The New World: How Does it Look Like?
=====================================

After this design almost happening as a natural consequence of an
initial set of constraints, the natural question arises: how would
programs look like in a C++ with these amenities?

Below are some considerations:

* Pointer arithmetic, unions, and casts must be reconsidered (a source
of unsafety not thoroughly discussed)

* Most types would be [collected]. Only a minority of types, those that
manage non-memory resources, would live in the deterministic realm.

* Efficiency of the system will not degrade compared to today's C++. The
reduced need for reference-counted resources would allow free and fast
pointer copying for many objects; the minority that need care in
lifetime management will stay tracked by the compiler, the way they
likely were manipulated (by hand) anyway.

* Given that the compiler can apply advanced analysis to eliminate
reference count manipulation in many cases, it is likely that the
quality of built-in reference counting would be superior to
manually-implemented reference counting, and on a par with advanced
manual careful manipulation of a mix of raw and smart pointers.

----------------------

Whew! Please send any comments you have to this group. Thanks!

Andrei

? ? ? [ See http://www.gotw.ca/resources/clcm.htm for info about ]
? ? ? [ comp.lang.c++.moderated. ? ?First time posters: Do this! ]

posted on 2006-03-21 10:01 Windreamer Is Not DREAMER 閱讀(635) 評論(1)  編輯 收藏 引用
Comments
  • # re: [ZZ]Reconciling Garbage Collection with Deterministic Finalization
    Francis Arcanum
    Posted @ 2006-10-28 01:33
    萬年不更新的家伙,悄悄bs一下^_^  回復  更多評論   

只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


 
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            欧美日韩午夜在线| 国产精品久久国产精麻豆99网站| 国产欧美视频一区二区| 亚洲欧美在线aaa| 亚洲伊人色欲综合网| 国产精品久久久久免费a∨| 亚洲一区欧美一区| 亚洲欧美日韩一区二区三区在线| 国产精品日韩欧美一区| 久久狠狠亚洲综合| 久久免费国产精品| 99国产精品久久久| 亚洲一区在线观看免费观看电影高清| 国产精品亚洲一区| 欧美91福利在线观看| 欧美精品免费播放| 欧美一区午夜精品| 久久久久综合| 亚洲午夜小视频| 欧美在线看片a免费观看| 在线日韩精品视频| 99视频有精品| 国模吧视频一区| 亚洲福利精品| 国产精品亚洲网站| 欧美大胆成人| 国产精品视频不卡| 亚洲福利视频二区| 国产精品夜夜嗨| 欧美激情亚洲另类| 国产三级欧美三级| 亚洲人体偷拍| 国产一区二区三区黄视频| 亚洲欧洲精品成人久久奇米网| 国产精品豆花视频| 欧美高清视频在线播放| 国产麻豆9l精品三级站| 欧美激情一级片一区二区| 国产精品人人做人人爽| 亚洲国产精品久久久久婷婷老年 | 欧美在线视频一区| 日韩一级网站| 久久婷婷丁香| 欧美一区二区三区四区在线观看| 欧美二区在线| 免费试看一区| 狠狠入ady亚洲精品经典电影| 一区二区三区高清不卡| 亚洲欧洲一区二区在线播放| 午夜一区二区三区在线观看| 亚洲午夜日本在线观看| 欧美韩日一区| 亚洲国产另类精品专区| 伊人久久大香线蕉综合热线| 亚洲欧美三级伦理| 性亚洲最疯狂xxxx高清| 欧美日韩中文字幕在线| 亚洲人成网站色ww在线| 亚洲人午夜精品| 免费久久精品视频| 欧美成熟视频| 亚洲人体偷拍| 欧美成人69av| 亚洲国产另类久久久精品极度| 在线播放亚洲| 久久视频这里只有精品| 蘑菇福利视频一区播放| 18成人免费观看视频| 老**午夜毛片一区二区三区| 蜜桃av一区二区三区| 亚洲国产成人精品女人久久久 | 国产在线观看精品一区二区三区| 99精品福利视频| 这里只有精品在线播放| 欧美日韩黄色大片| 一本一本久久a久久精品综合麻豆 一本一本久久a久久精品牛牛影视 | 另类综合日韩欧美亚洲| 影音先锋日韩资源| 麻豆精品在线视频| 亚洲日本欧美在线| 亚洲午夜在线| 国产日韩欧美日韩| 久久精品人人爽| 亚洲高清不卡一区| 一区二区三区日韩在线观看| 国产精品久久国产精品99gif| 亚洲欧美日韩精品久久久久| 久久女同精品一区二区| 亚洲黄网站在线观看| 欧美日韩一区在线| 小处雏高清一区二区三区| 久久亚洲私人国产精品va| 亚洲精品国产精品乱码不99按摩| 欧美日韩在线免费视频| 亚洲欧美视频在线观看视频| 六十路精品视频| 亚洲最新在线视频| 国产人久久人人人人爽| 蜜月aⅴ免费一区二区三区| 99re6这里只有精品| 久久精品视频免费| 9久re热视频在线精品| 国产日韩欧美成人| 欧美黄色aa电影| 午夜欧美大片免费观看| 亚洲福利视频二区| 欧美在线视频观看免费网站| 亚洲国产中文字幕在线观看| 国产精品久久久久久一区二区三区| 久久久777| 亚洲一二三区在线观看| 欧美激情一区二区三区四区| 久久国产精品第一页| 日韩视频在线观看| 怡红院精品视频在线观看极品| 欧美日韩亚洲一区在线观看| 久久婷婷影院| 午夜天堂精品久久久久| 亚洲免费av观看| 亚洲第一成人在线| 久久一区激情| 欧美一区二区三区男人的天堂| 日韩视频一区二区在线观看| 国产在线精品二区| 国产精品夜色7777狼人| 欧美日韩精品系列| 男女激情久久| 巨胸喷奶水www久久久免费动漫| 亚洲欧美春色| 亚洲午夜精品久久久久久浪潮| 亚洲国产欧美一区二区三区同亚洲| 久久婷婷激情| 久久精品免费播放| 午夜精品久久久久久久久久久久| 一区二区三区精品久久久| 亚洲欧洲精品一区二区三区不卡 | 亚洲人在线视频| 麻豆精品一区二区综合av| 欧美亚洲在线观看| 亚洲一区二区在线免费观看视频| 日韩视频一区二区三区在线播放免费观看 | 国产日韩亚洲欧美精品| 国产精品黄视频| 国产精品va在线播放| 欧美欧美全黄| 欧美日韩激情小视频| 欧美日韩国产精品专区| 欧美精品自拍| 欧美国产综合视频| 欧美激情一区二区三区在线| 欧美成人午夜剧场免费观看| 欧美成人精品一区二区| 女主播福利一区| 欧美国产大片| 欧美日韩在线播| 国产精品久久久久久久7电影| 国产精品久久久久久妇女6080 | 亚洲精品一区二区三区av| 亚洲精品字幕| 9国产精品视频| 亚洲欧美日韩一区二区| 久久精品人人做人人爽电影蜜月| 久久精品99久久香蕉国产色戒 | 一本大道av伊人久久综合| 亚洲香蕉成视频在线观看| 午夜视频一区二区| 裸体素人女欧美日韩| 亚洲高清免费在线| 亚洲一二三区在线| 久久久久国色av免费观看性色| 蜜臀av一级做a爰片久久| 欧美日韩一区二区在线 | 欧美精品情趣视频| 国产精品你懂的| 激情综合网址| 中日韩视频在线观看| 久久精品人人做人人综合| 欧美激情视频一区二区三区免费| 日韩午夜免费视频| 午夜一区二区三区不卡视频| 快播亚洲色图| 国产乱人伦精品一区二区| 亚洲国产精品一区二区久| 亚洲一区在线免费| 开心色5月久久精品| 一区二区三区高清不卡| 久久久久青草大香线综合精品| 欧美日韩免费一区二区三区视频| 国产原创一区二区| 一本色道精品久久一区二区三区| 久久国产精品久久久久久电车| 亚洲国产一成人久久精品| 欧美夜福利tv在线| 国产精品mm| 亚洲七七久久综合桃花剧情介绍| 欧美一区二区三区四区夜夜大片| 亚洲激情影视| 麻豆精品传媒视频| 国产一区av在线| 午夜精品久久久久影视 |