- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
stack allocation?
Mon, 2010-04-26, 15:29
Just a quick query: Has there been any serious discussion or proposals for supporting stack allocation explicitly in the scala language? By this I mean something along the lines of struct types in C#, but in general terms: a lightweight user defined type system where instances of the type are not allocated on the heap by default(there should be support for boxing), and which support value type semantics (copy on assignment is the default).
This functionality is generally needed for most soft real-time software (not just games) that has to run on a sub-standard VM (pretty much any VM that runs on a mobile device these days), unless the code is vigorously optimized to never generate garbage, which leads to a coding style that is often difficult to read and maintain. FYI: for this class of software, we are generally willing to sacrifice a little bit of maximum throughput for a more predictable/consistent step time, if necessary.
There is no explicit support for stack-allocation of user types in the Java VM (I believe there is in CLI, but I'm not sure - it may just be a C#-ism). Supposedly, the JIT of the java VM can automatically use stack allocation where appropriate, but in practice it doesn't work reliably, and again is not available on all VMs (i.e. there's likely no chance that a mobile VM would support it).
However, I've seen the use of byte code instrumentation as part of a build process that inserts the needed stack-allocation code. For example, there is the JStackAlloc framework, which is used in the JBullet physics engine to great effect.
http://www.javagaming.org/index.php/topic,18843.0.html
If this kind of instrumentation were built into the language, it would eliminate the need for a special build process or the need to redesign a library to aggressively reduce garbage collections at the expense of readability/maintainability.
This functionality is generally needed for most soft real-time software (not just games) that has to run on a sub-standard VM (pretty much any VM that runs on a mobile device these days), unless the code is vigorously optimized to never generate garbage, which leads to a coding style that is often difficult to read and maintain. FYI: for this class of software, we are generally willing to sacrifice a little bit of maximum throughput for a more predictable/consistent step time, if necessary.
There is no explicit support for stack-allocation of user types in the Java VM (I believe there is in CLI, but I'm not sure - it may just be a C#-ism). Supposedly, the JIT of the java VM can automatically use stack allocation where appropriate, but in practice it doesn't work reliably, and again is not available on all VMs (i.e. there's likely no chance that a mobile VM would support it).
However, I've seen the use of byte code instrumentation as part of a build process that inserts the needed stack-allocation code. For example, there is the JStackAlloc framework, which is used in the JBullet physics engine to great effect.
http://www.javagaming.org/index.php/topic,18843.0.html
If this kind of instrumentation were built into the language, it would eliminate the need for a special build process or the need to redesign a library to aggressively reduce garbage collections at the expense of readability/maintainability.