general questions on reference types versus value types...

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Dec 1 12:55:41 PST 2014


On 12/1/14 3:22 PM, Suliman wrote:
> Could anybody explain why there is opinion that stack is fast and the
> heap is slow. All of them are located in the same memory. So the access
> time should be equal.

Measure it :)

But short answer is twofold:

1. stack is usually hot in the local processor cache, so it's almost 
always the fastest to access.
2. The *access* to the heap memory isn't necessarily slower, as the heap 
memory can just as easily be in the cache, it's *allocating* heap memory 
that is slower (and vastly so) than allocating stack memory.

-Steve


More information about the Digitalmars-d-learn mailing list