Arrays

D provides associative arrays that are similar to hashtables and dictionaries in other languages. The index into the array can be a n-tuple of values, separated by commas. arrayname[pid, probefunc, "bork"] = 23; is a valid assignment. The types of the array index must match for every assignment, and the assigned values must be uniform. You cannot nest arrays.

Example 9.9 calculates the wall-clock time it takes to execute the read() system call:

Example 9.9. readtime.d

s​y​s​c​a​l​l​:​:​r​e​a​d​:​e​n​t​r​y​ {​ ​ ​ ​ ​s​e​l​f​-​>​t​s​[​p​i​d​,​ ​p​r​o​b​e​f​u​n​c​]​ ​=​ ​t​i​m​e​s​t​a​m​p​;​ }​ s​y​s​c​a​l​l​:​:​r​e​a​d​:​r​e​t​u​r​n​ /​s​e​l​f​-​>​t​s​[​p​i​d​,​ ​p​r​o​b​e​f​u​n​c​]​ ​!​=​ ​0​/​ {​ ​ ​ ​ ​d​e​l​t​a​ ​=​ ​t​i​m​e​s​t​a​m​p​ ...

Get Advanced Mac OS X Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.