This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Re: tuples and specialization - surprise

2 replies
H-star Development
Joined: 2010-04-14,
User offline. Last seen 2 years 26 weeks ago.
i kinda expected tuple2specialized to be:

class Tuple2Double(val a:double, val b:double)

not

class Tuple2Double(val a:double, val b:double, val unused1:Object, val unused2:Object)

Am 18.01.2012 21:33, schrieb √iktor Ҡlang:
2mkdimOiDPaW-JwnHt7jh_CO1OPNA [at] mail [dot] gmail [dot] com" type="cite">

On Wed, Jan 18, 2012 at 9:29 PM, HamsterofDeath <h-star [at] gmx [dot] de" rel="nofollow">h-star@gmx.de> wrote:

why are there 4 members instead of 2?

How else do you store a primitive without boxing it?

--
Viktor Klang

Akka Tech Lead Typesafe - The software stack for applications that scale

Twitter: @viktorklang

ichoran
Joined: 2009-08-14,
User offline. Last seen 2 years 3 weeks ago.
Re: tuples and specialization - surprise
Tuple2 is a class from which Tuple2$mcDD$sp inherits.

Therefore, unfortunately, it inherits the now-unused fields _1 and _2 (and the extra 8 bytes of storage that those require).

A scheme where there was a common base class that has no fields (just accessors) and the object-containing fields were in the (default) subclass would avoid this problem (albeit at the cost of confusing all the class names even when the specialized version wasn't used).

  --Rex

2012/1/18 HamsterofDeath <h-star@gmx.de>
i kinda expected tuple2specialized to be:

class Tuple2Double(val a:double, val b:double)

not

class Tuple2Double(val a:double, val b:double, val unused1:Object, val unused2:Object)

Am 18.01.2012 21:33, schrieb √iktor Ҡlang:


On Wed, Jan 18, 2012 at 9:29 PM, HamsterofDeath <h-star@gmx.de> wrote:

why are there 4 members instead of 2?

How else do you store a primitive without boxing it?

--
Viktor Klang

Akka Tech Lead Typesafe - The software stack for applications that scale

Twitter: @viktorklang


Matthew Pocock 3
Joined: 2010-07-30,
User offline. Last seen 42 years 45 weeks ago.
Re: tuples and specialization - surprise


On 18 January 2012 23:04, Rex Kerr <ichoran@gmail.com> wrote:
Tuple2 is a class from which Tuple2$mcDD$sp inherits.

Therefore, unfortunately, it inherits the now-unused fields _1 and _2 (and the extra 8 bytes of storage that those require).

A scheme where there was a common base class that has no fields (just accessors) and the object-containing fields were in the (default) subclass would avoid this problem (albeit at the cost of confusing all the class names even when the specialized version wasn't used).

Right, so if a class is specialized, perhaps this should cause specific sub-classes to be generated for the Any cases in addition to the primitive ones? Who knows, it may even clean up some of the implementation ;)
Matthew 


  --Rex

2012/1/18 HamsterofDeath <h-star@gmx.de>
i kinda expected tuple2specialized to be:

class Tuple2Double(val a:double, val b:double)

not

class Tuple2Double(val a:double, val b:double, val unused1:Object, val unused2:Object)

Am 18.01.2012 21:33, schrieb √iktor Ҡlang:


On Wed, Jan 18, 2012 at 9:29 PM, HamsterofDeath <h-star@gmx.de> wrote:

why are there 4 members instead of 2?

How else do you store a primitive without boxing it?

--
Viktor Klang

Akka Tech Lead Typesafe - The software stack for applications that scale

Twitter: @viktorklang





--
Dr Matthew PocockIntegrative Bioinformatics Group, School of Computing Science, Newcastle Universitymailto: turingatemyhamster@gmail.com gchat: turingatemyhamster@gmail.commsn: matthew_pocock@yahoo.co.uk irc.freenode.net: drdozerskype: matthew.pococktel: (0191) 2566550mob: +447535664143

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland