O'Reilly logo

Advanced Mac OS X Programming: The Big Nerd Ranch Guide by Mark Dalrymple

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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​ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required