Stack allocation of dynamic arrays?

Kirk McDonald kirklin.mcdonald at gmail.com
Wed Aug 8 13:37:39 PDT 2007


Robert Fraser wrote:
> I know that by using "scope" you can allocate a class on the stack rather than the heap. For this line:
> 
> scope int[] arr = new int[5000];
> 
> ... is arr allocated on the heap or on the stack?

The spec implies it should be on the stack:

"If a NewExpression is used as an initializer for a function local 
variable with scope storage class, and the ArgumentList to new is empty, 
then the instance is allocated on the stack rather than the heap or 
using the class specific allocator."

Even if it isn't actually on the stack, it behaves exactly as though it 
were.

-- 
Kirk McDonald
http://kirkmcdonald.blogspot.com
Pyd: Connecting D and Python
http://pyd.dsource.org


More information about the Digitalmars-d-learn mailing list