My Issues with Slices and AAs

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Fri Mar 2 08:33:21 PST 2012


On 3/2/12 10:24 AM, Kevin Cox wrote:
> Although if slices are still built-in but act as if they are part of an
> interface will that slow them down?  And, if so where is the slowdown?
> Is it in the interfaces?

Yes, a traditional interface (in the sense I gather you use it) uses 
indirection by definition, meaning the user has access to a reference, 
which points to a table of primitive functions that in turn are 
implemented by various concrete implementers. The scheme requires 
dynamic allocation not only of the data, but of the concrete objects 
managing it as well.

In contrast, a slice is simply a pair: a pointer to the data and the 
extent of the data. Accessing a slice is as direct as indexing the 
pointer after a bounds check.


Andrei


More information about the Digitalmars-d mailing list