Thunk

Thunk

Thunk es un término usado en la jerga del desarrollo de software que designa la llamada o invocación a un código que pertenece a otra plataforma o a otro Framework. En el paso de 16 a 32 bit por ejemplo, los sistemas operativos (OS/2, Windows NT etc.) podían resolver código de 16 bit a través de la transformación de los parámetros de llamadas y direcciones, de modo tal que fue posible seguir utilizando los programas de 16 bit.

En el desarrollo de software moderno, un thunk es la llamada del código nativo desde el código gestionado y viceversa (véase por ejemplo Java Native Access o .NET P/Invoke). Es decir, se trata de una plataforma de transición, en la que las convenciones y/o parámetros de invocación tienen que transformarse correspondientemente (Marshalling). El lenguaje de programación C++/CLI del .NET-Framework de Microsoft fue concebido especialmente para posibilitar tales thunks en ambas direcciones:

Invocación por «gestionada» a «no gestionada»

Sea dada una clase nativa en C++, por ejemplo un proyecto C++ o como parte integrante de un proyecto C++/CLI, que se utilizará más abajo en código gestionado:

 public class CNativeClass
 {
 private:
   int m_i;
 public:
   void SetValue( int i )
   {
     m_i = i;
   }
 };

La clase gestionada C++/CLI (que en esta forma puede ser directamente instanciada, por ejemplo, en C#), la cual utiliza la clase nativa mostrada anteriormente:

 public ref class CManagedClass
 {
 public:
   CManagedClass()
   {
     System::Int32 i = 42;
     CNativeClass* pNativeClass = new CNativeClass();
     pNativeClass->SetValue( i ); // Implementación del tipo de datos
     delete pNativeClass;
   }
 };

Invocación por «no gestionada» a «gestionada»

La clase gestionada C++/CLI :

 public ref class CManagedClass
 {
 private:
   System::Int32 m_i;
 public:
   void SetValue( int i )
   {
     m_i = i; // Implementación del tipo de datos
   }
 };

Las clases nativas C++ en un proyecto C++/CLI. Aquí se puede ver que también el camino inverso es posible, es decir, instanciar el código gestionado dentro de una clase no gestionada. La condición es, sin embargo, que se trate de un proyecto C++/CLI, de modo tal que el compilador comprenda la correspondiente sintaxis. El thunk ya aparece en la instrucción «gcnew», ya que aquí se invoca al constructor de la clase gestionada:

 public class CNativeClass
 {
 public:
   void Foo()
   {
     int i = 42;
     CManagedClass^ pManagedClass = gcnew CManagedClass();
     pManagedClass->SetValue( i );
   }
 };

Bibliografía

  • Marcus Heege: Expert C++/CLI. Apress Verlag, Berkeley 2007, ISBN 978-1-59059-756-9, Capítulo 9, p. 203 y siguientes.

Wikimedia foundation. 2010.

Игры ⚽ Поможем сделать НИР

Mira otros diccionarios:

  • thunk — sound of impact, attested from 1952, echoic …   Etymology dictionary

  • thunk — ☆ thunk1 [thuŋk ] n. [echoic] an abrupt, muffled sound, as of an ax hitting a tree trunk vi. to make such a sound thunk2 [thuŋk] vt., vi. Dial. pt. & pp. of THINK1 …   English World dictionary

  • Thunk — The word thunk has at least three related meanings in computer science. A thunk may be: * a piece of code to perform a delayed computation (similar to a closure) * a feature of some virtual function table implementations (similar to a wrapper… …   Wikipedia

  • Thunk — Als Thunk bezeichnet man im Jargon der Softwareentwicklung den Aufruf von Code, der einer anderen Plattform oder einem anderen Framework angehört. Bei der Umstellung von 16 auf 32 Bit beispielsweise, konnten die Betriebssysteme (OS/2, Windows NT… …   Deutsch Wikipedia

  • thunk — 1. verb /θʌŋk/ to strike against something, without breakage, making a thunk sound Who would have thunk those guys would have a problem with a little lye? 2. noun /θʌŋk/ a) a delayed computation b) In the Scheme programming language, a function… …   Wiktionary

  • Thunk — jocular past tense or past participle of think : I thunk and thunk (by analogy with sink/sunk ) …   Dictionary of Australian slang

  • thunk — I Australian Slang jocular past tense or past participle of think : I thunk and thunk (by analogy with sink/sunk ) II Mawdesley Glossary a leather boot lace, a leather thong …   English dialects glossary

  • thunk — Used in place of thought or think. Whoodah thunk I d be the one they picked. Or; I guess I didn t thunk it through all the way …   Dictionary of american slang

  • thunk — Used in place of thought or think. Whoodah thunk I d be the one they picked. Or; I guess I didn t thunk it through all the way …   Dictionary of american slang

  • thunk — I. dialect past and past participle of think II. noun Etymology: imitative Date: 1947 a flat hollow sound III. intransitive verb Date: 1949 to produce a flat hollow sound ; make a thunk …   New Collegiate Dictionary

Compartir el artículo y extractos

Link directo
Do a right-click on the link above
and select “Copy Link”