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

Re: how can one avoid boxing when using function

No replies
Jesse Eichar 2
Joined: 2011-04-06,
User offline. Last seen 42 years 45 weeks ago.
Ok thanks for making me look like a liar. ;P  I saw those classes but when I did a debug session in eclipse it did the boxing.  I compiled externally and attached the debugger to that and it is now behaving correctly.  Must have had something to do with my eclipse config.  I should look to see if the no specialized flag is check.
My apologies for the noise.
Jesse

On Thu, Sep 22, 2011 at 9:30 AM, Rex Kerr <ichoran [at] gmail [dot] com> wrote:
Are you sure you looked at the bytecode for B$mcI$sp and foreach$mcI$sp?
  --Rex

On Thu, Sep 22, 2011 at 3:13 AM, Jesse Eichar <jesse [dot] eichar [at] gmail [dot] com> wrote:
Hi,  I am trying to figure out how to avoid boxing because the performance hit is killing me.  As an experiment I wrote the following code:
object X {  def main(args:Array[String]) { val b = new B[Int](3)     while(true) {      b.foreach(_ + 1)     }  }}
class B[@specialized(Int)A](val a:A) { def foreach(f: A => Unit) = f(a) }
Sadly, when I look at the byte code the foreach method is still boxing.  In my actual application I am writing a custom collection that always contains ints and I need to get around the boxing.  Any suggestions?
Jesse


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