Share to: share facebook share twitter share wa share telegram print page

Double-chance function

In software engineering, a double-chance function is a software design pattern with a strong application in cross-platform and scalable development.

Examples

Computer graphics

Consider a graphics API with functions to DrawPoint, DrawLine, and DrawSquare. It is easy to see that DrawLine can be implemented solely in terms of DrawPoint, and DrawSquare can in turn be implemented through four calls to DrawLine. If you were porting this API to a new architecture you would have a choice: implement three different functions natively (taking more time to implement, but likely resulting in faster code), or write DrawPoint natively, and implement the others as described above using common, cross-platform, code. An important example of this approach is the X11 graphics system, which can be ported to new graphics hardware by providing a very small number of device-dependent primitives, leaving higher level functions to a hardware-independent layer.[1][2]

The double-chance function is an optimal method of creating such an implementation, whereby the first draft of the port can use the "fast to market, slow to run" version with a common DrawPoint function, while later versions can be modified as "slow to market, fast to run". Where the double-chance pattern scores high is that the base API includes the self-supporting implementation given here as part of the null driver, and all other implementations are extensions of this. Consequently, the first port is, in fact, the first usable implementation.

One typical implementation in C++ could be:

 class CBaseGfxAPI {
     virtual void DrawPoint(int x, int y) = 0; /* Abstract concept for the null driver */
     virtual void DrawLine(int x1, int y1, int x2, int y2) { /* DrawPoint() repeated */}
     virtual void DrawSquare(int x1, int y1, int x2, int y2) { /* DrawLine() repeated */}
 };

 class COriginalGfxAPI : public CBaseGfxAPI {
     virtual void DrawPoint(int x, int y) { /* The only necessary native calls */ }
     virtual void DrawLine(int x1, int y1, int x2, int y2) { /* If this function exists a native DrawLine
                                                                routine will be used. Otherwise the base
                                                                implementation is run. */}
 };

 class CNewGfxAPI : public CBaseGfxAPI {
     virtual void DrawPoint(int x, int y) { /* The only necessary for native calls */ }
 };

Note that the CBaseGfxAPI::DrawPoint function is never used, per se, as any graphics call goes through one of its derived classes. So a call to CNewGfxAPI::DrawSquare would have its first chance to render a square by the CNewGfxAPI class. If no native implementation exists, then the base class is called, at which point the virtualization takes over and means that CNewGfxAPI::DrawLine is called. This gives the CNewGfxAPI class a “second chance” to use native code, if any is available.

With this method it is, theoretically, possible to build an entire 3D engine (applying software rasterizing) using only one native function in the form of DrawPoint, with other functions being implemented as and when time permits. In practice this would be hopelessly slow, but it does demonstrate the possibilities for double-chance functions.

References

  1. ^ Susan Angebranndt, Raymond Drewry, Philip Karlton, Todd Newman, "Definition of the Porting Layer for the X v11 Sample Server", MIT, 1988.
  2. ^ Susan Angebranndt, Raymond Drewry, Philip Karlton, Todd Newman, "Strategies for Porting the X v11 Sample Server", Mit 1988.
  • Goodwin, Steven (2005). Cross-Platform Game Programming. Charles River Media. ISBN 1-58450-379-3.

Read other articles:

Staatliches Wilhelmsgymnasium Schulform Humanistisches Gymnasium Gründung 1559 Adresse Thierschstraße 4680538 München Land Bayern Staat Deutschland Koordinaten 48° 8′ 17″ N, 11° 35′ 19″ O48.13805555555611.588611111111Koordinaten: 48° 8′ 17″ N, 11° 35′ 19″ O Träger staatlich Schüler 553 (Schuljahr 2022/23)[1] Lehrkräfte 47 Leitung Michael Hotz Website www.wilhelmsgymnasium.de Das Staatliche Wilhe...

CDP in Virginia, United StatesChester, VirginiaCDPChester Station replica in downtown ChesterLocation of Chester, VirginiaCoordinates: 37°21′12″N 77°26′9″W / 37.35333°N 77.43583°W / 37.35333; -77.43583CountryUnited StatesStateVirginiaCountyChesterfieldArea • Total13.3 sq mi (34.4 km2) • Land13.2 sq mi (34.1 km2) • Water0.1 sq mi (0.3 km2)Elevation174 ft (53 m)Populati...

School in Kolkata, India This article does not cite any sources. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Dum Dum Kishore Bharati High School – news · newspapers · books · scholar · JSTOR (December 2019) (Learn how and when to remove this template message) Dum Dum Kishore Bharati High SchoolAddressP2-A, Motijheel AvenueDum DumKolkata, West Bengal 700 074Indi...

Place in Styria, SloveniaTovstoTovstoLocation in SloveniaCoordinates: 46°10′7.66″N 15°14′44.86″E / 46.1687944°N 15.2457944°E / 46.1687944; 15.2457944Country SloveniaTraditional regionStyriaStatistical regionSavinjaMunicipalityLaškoArea • Total1.97 km2 (0.76 sq mi)Elevation322.8 m (1,059.1 ft)Population (2002) • Total155[1] Tovsto (pronounced [ˈtoːu̯stɔ]) is a settlement in the Munici...

This article contains content that is written like an advertisement. Please help improve it by removing promotional content and inappropriate external links, and by adding encyclopedic content written from a neutral point of view. (March 2021) (Learn how and when to remove this template message) Alliance for the Great LakesAbbreviationAGLFormation1970TypeNon-governmental organizationHeadquartersChicago, IllinoisRegion served United StatesChairLori ColmanWebsitewww.greatlakes.org The Alliance ...

Gods of Manhattan First editionAuthorScott MebusCover artistBrandon DormanCountryUnited StatesLanguageEnglishSeriesGods of ManhattanSubjectChildren's fiction, FantasyPublisherDutton PenguinPublication dateApril 17, 2008Media typePrint (hardback, paperback), e-book, audiobookPages272 pagesISBN978-0-525-47955-0Followed bySpirits in the Park  Gods of Manhattan is a 2008 children's novel by Scott Mebus.[1] The book was first released on April 17, 2008 through Dutton Pe...

Human mitochondrial DNA haplogroup This article is about the human mtDNA haplogroup. For the human Y-DNA haplogroup, see Haplogroup H (Y-DNA). Haplogroup HPossible time of origin20,000–25,000 YBPPossible place of originSouthwest Asia (West Asia or Western Asia), Lesser CaucasusAncestorHV[1]DescendantsH* lineages; subclades H1, H2, H3, H4, H5'36, H6, H7, H8, H9, H10, H11, H12, H13, H14, H15, H16, H18, H19, H20, H22, H23, H24, H25, H26, H28, H29, H31, H32, H33, H34, H35, H37, H38, H39...

Iraqi Isma'ili missionary (died 914) Abu'l-Qāsim al-Ḥasan ibn Faraj ibn Ḥawshab ibn Zādān al-Najjār al-Kūfī (Arabic: أبو القاسم الحسن ابن فرج بن حوشب زاذان النجار الكوفي; died 31 December 914), better known simply as Ibn Ḥawshab, or by his honorific of Manṣūr al-Yaman (Arabic: منصور اليمن, lit. 'Conqueror of Yemen'), was a senior Isma'ili missionary (dāʿī) from the environs of Kufa. In cooperation with Ali ib...

1935 film The Pecos KidDirected byHarry L. FraserWritten byHenry Hess (screenplay)Ted Tuttle (story)Produced byWilliam BerkeStarringFred Kohler, Jr.Edited byArthur A. BrooksDistributed byCommodore PicturesRelease date April 1, 1935 (1935-04-01) Running time60 minutesCountryUnited StatesLanguageEnglish The Pecos Kid is a 1935 American Western film directed by Harry L. Fraser.[1] Plot summary Land Baron James Grayson and his gang steal the Pecos' family Rancho and kill th...

American actress (Born 2012) This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these template messages) The topic of this article may not meet Wikipedia's notability guideline for biographies. Please help to demonstrate the notability of the topic by citing reliable secondary sources that are independent of the topic and provide significant coverage of it beyond a mere trivial mention. If notability cannot be shown...

Chinese television network This article is about the Chinese Television Channel. For the parent, see Fujian Radio Film and TV Group. This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these template messages) This article relies largely or entirely on a single source. Relevant discussion may be found on the talk page. Please help improve this article by introducing citations to additional sources.Find sources: ...

Voce principale: Città. Questa voce o sezione sull'argomento diritto pubblico non cita le fonti necessarie o quelle presenti sono insufficienti. Puoi migliorare questa voce aggiungendo citazioni da fonti attendibili secondo le linee guida sull'uso delle fonti. Questa voce sugli argomenti diritto pubblico e storia è solo un abbozzo. Contribuisci a migliorarla secondo le convenzioni di Wikipedia. Segui i suggerimenti del progetto di riferimento. Corona per il titolo di città utiliz...

Battle of the Second Fitna (680s-690s). It was fought in mid-October 691 near present-day Baghdad For the battle during the revolt of Ibn al-Ash'ath, see Battle of Maskin (701). Battle of MaskinPart of the Second FitnaDateMid-October 691LocationDayr al-Jathaliq in Maskin district, 50–55 kilometers (31–34 mi) north of present-day Baghdad33°49′24″N 44°14′24″E / 33.82333°N 44.24000°E / 33.82333; 44.24000Result Umayyad victoryBelligerents Umayyad Calip...

Perceived video degradation Video quality is a characteristic of a video passed through a video transmission or processing system that describes perceived video degradation (typically, compared to the original video). Video processing systems may introduce some amount of distortion or artifacts in the video signal that negatively impacts the user's perception of a system. For many stakeholders in video production and distribution, assurance of video quality is an important task. Video quality...

Internet divide for communication technology The digital divide is a term used to describe the disadvantage in access to information which people without access to ICT suffer.[1] Nigeria's digital divide refers to the inequality of Nigerian individuals, groups, or organizations with regard to access to Information and communications technology (ICT) infrastructure or to the internet for daily activities.[2] The digital divide has been attributed to many factors among which is ...

American soap opera television series Bare EssenceGenreSoap operaBased onBare Essence (1980)by Meredith RichDeveloped byRobert HamiltonWritten by Robert Hamilton Directed byWalter GraumanStarring Genie Francis Jennifer O'Neill Lee Grant John Dehner Ian McShane Michael Woods Jonathan Frakes Wendy Fulton Jaime Lyn Bauer Al Corley Susan French Theme music composerBilly GoldenbergComposerMarvin LairdCountry of originUnited StatesOriginal languageEnglishNo. of seasons1No. of episodes11ProductionEx...

Ferry route from Kettering to Bruny Island in Tasmania, Australia This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Bruny Island Ferry – news · newspapers · books · scholar · JSTOR (September 2007) (Learn how and when to remove this template message) The Bruny Island ferry Mirambeena en route from Kettering to...

Parque de Bombas, built in 1882, is one of Puerto Rico's most photographed structures Ponce, Puerto Rico's second-largest city outside the San Juan metropolitan area, receives over 100,000 visitors annually.[1] Ponce's sights include monuments and architecture, such as its Monumento a la Abolición de la Esclavitud and Residencia Armstrong-Poventud, and pink marble curbs and chamfered streets corners, as well as historic houses, castles and concert halls. There are also more modern at...

English actress Jane LeevesLeeves in 2012BornJane Elizabeth Leeves (1961-04-18) 18 April 1961 (age 62)Ilford, Essex, EnglandOccupationActressYears active1981–presentSpouse Marshall Coben ​(m. 1996)​Children2 Jane Elizabeth Leeves (born 18 April 1961)[1] is an English actress, best known for her role as Daphne Moon on the NBC sitcom Frasier (1993–2004), for which she was nominated for an Emmy Award and a Golden Globe Award.[2][3 ...

Pour les articles homonymes, voir Jean II. Jean II de TrébizondeAspre d'argent, avers figurant Jean II de Trébizonde (avant 1297).FonctionEmpereur de Trébizonde1280 - 16 mars 1297Georges Ier de TrébizondeAlexis II de TrébizondeBiographieNaissance 1262TrébizondeDécès 16 août 1297Empire de TrébizondeFamille ComnènePère Manuel Ier de TrébizondeMère Irene Syrikaina (en)Fratrie Andronic II de Trébizonde (demi-frère consanguin)Théodora de Trébizonde &...

Kembali kehalaman sebelumnya