Is `alias this` a mistake?

wjoe invalid at example.com
Fri Aug 6 12:27:55 UTC 2021


On Thursday, 5 August 2021 at 17:44:48 UTC, H. S. Teoh wrote:
> On Thu, Aug 05, 2021 at 05:24:56PM +0000, IGotD- via 
> Digitalmars-d wrote: [...]
> Since the stack is almost constantly being accessed in the 
> course of a program's execution, it remains in cache and so is 
> much more cache-friendly than dereferencing a pointer to the

This raises the question how does this apply to a CPU that has a 
L1 cache of 512KiB, a L3 of 4MiB for a program with a stack size 
of 8MiB ?
As far as I'm aware stack memory is residing on the heap so it 
will need to be allocated on program start up.
So in theory...
if we were pre-allocating a chunk of memory on the heap at 
program startup and used that to store our data (like on a 
stack), the cost of allocation would have been paid, once we need 
to use it, and would only have to be done once. "Deallocation" 
cost for data using this "stack" should be getting pretty close 
to that of *the* stack (which is basically a subtraction). 
Deallocation cost for the block of heap memory on program 
termination doesn't matter.
In practice the "stack" would probably be closer to a pool and 
memory management a bit more involved than an 
addition/subtraction.

A cache line is usually much smaller than L1 at just a few data 
words. So once the pre-fetcher is set up, and the memory in 
question is residing in L1, there shouldn't be a difference 
anymore.

Therefore I would reason that utilizing cache line bandwidth 
efficiently is important and whether the data resides on the heap 
or stack is secondary (i.e. what a struct (doesn't) contain is 
more important than where it's stored).



More information about the Digitalmars-d mailing list