EETimes

Embedded Systems December 2000 Vol13_13

Issue link: http://dc.ee.ubm-us.com/i/71850

Contents of this Issue

Navigation

Page 157 of 197

FIGURE 1 :An inside look at an example-dynamic array int d[2] = {2, 3}; free-ptr = OxOOO21fSO totaL array size = 36 bytes A. int st[2] &arr {Q, -1}; Location contents -> Oxffbefaf8 OxOOO21f68 <- arr &arr[ 0][-1] -> OxOOO21fSO Oxffffffff <- arr[ 0][-1] (-1) &arr[ 0][ 0] -> OxOOO21fS4 OxOOOOOOOO <- arr[ 0][ 0] ( 0) &arr[ 0][ 1] -> OxOOO21fS8 OxOOOOOOO1 <- arr[ 0][ 1] ( 1) &arr[ 1][-1] -> OxOOO21fSc OxOOOOOOOO <- arr[ 1][-1] ( 0) &arr[ 1][ 0] -> OxOOO21f60 OxOOOOOOO1 <- arr[ 1][ 0] ( 1) &arr[ 1][ 1] -> OxOOO21f64 OxOOOOOOO2 <- arr[ 1][ 1] ( 2) &arr[ 0] &arr[ 1] -> OxOOO21f68 OxOOO21fS4 <- arr[ 0] -> OxOOO21f6c OxOOO21f60 <- arr[ 1] OxOOO21f70 OxOOOOOOOO B. int st[2] &arr {-1, -1}; Location contents -> Oxffbefaf8 OxOOO21f6c <- arr &arr[-1][-1] -> OxOOO21fSO Oxfffffffe <- arr[-1][-1] (-2) &arr[-1][ 0] -> OxOOO21fS4 Oxffffffff <- arr[-1][ 0] (-1) &arr[-1][ 1] -> OxOOO21fS8 OxOOOOOOOO <- arr[-1][ 1] ( 0) &arr[ 0][-1] -> OxOOO21fSc Oxffffffff <- arr[ 0][-1] (-1) &arr[ 0][ 0] -> OxOOO21f60 OxOOOOOOOO <- arr[ 0][ 0] ( 0) &arr[ 0][ 1] -> OxOOO21f64 OxOOOOOOO1 <- arr[ 0][ 1] ( 1) &arr[-1] &arr[ OJ -> OxOOO21f68 OxOOO21fS4 <- arr[-1] -> OxOOO21f6c OxOOO21f60 <- arr[ 0] OxOOO21f70 OxOOOOOOOO c. int st[2] = {-2S, -1}; Location contents &arr -> Oxffbefaf8 OxOOO21fcc <- arr &arr[-2S][-1] -> OxOOO21fSO Oxffffffe6 <- arr[-2S][-1] (-26) &arr[-2S][ 0] -> OxOOO21fS4 Oxffffffe7 <- arr[-2S][ 0] (-2S) &arr[-2S][ 1] -> OxOOO21fS8 Oxffffffe8 <- arr[-2S][ 1] (-24) &arr[-24][-1] -> OxOOO21fSc Oxffffffe7 <- arr[-24][-1] (-2S) &arr[-24][ 0] -> OxOOO21f60 Oxffffffe8 <- arr[-24][ 0] (-24) &arr[-24][ 1] -> OxOOO21f64 Oxffffffe9 <- arr[-24][ 1] (-23) &arr[-2S] &arr[-24] -> OxOOO21f68 OxOOO21fS4 <- arr[-2S] -> OxOOO21f6c OxOOO21f60 <- arr[-24] OxOOO21f70 OxOOOOOOOO 156 DECEMBER 2000 Embedded Systems Programming - '-. make th e routines fully reenU"ant. I use them in a Solaris MT I MP I RT environme nt in which full reen tra ncy a llows me to avoid protecting th e cod e wiUl mutexes. Alignment of the d ata area is th e alignme nt of the first a rgume nt si ze- of (), while th e a lignme nt of the point- er area is sizeof(char *). The data comes first, and the assumption he re is that the vaLLocO (for daavO) and whatever allocation ro utine is used be tween dasO and daaO will align at th e most stringent boundary, thus accommodating the clata area a lig n- me nt. The po in ter area comes second and may, d e pending o n the total size of th e d ata a rea, neecl to be align ed o n a sizeof(char *) bo undary. The base pointe r of th e pointer area is tested for a lignmen t in the ma in ro utine before po inter array calculations, and its alignme nt adjusted if necessary. The easiest way to see how the pointer levels are being calculated is to put a printfO at th e sta rt of the ptr_initO routine and print the level and dim_ind[] array. This gives you an idea as to how the arrays of pointe rs a t each level a re being positioned. Additionally, you could print o ut th e pointer values themselves and walk through th em to verify that the po in t- er to po inte r to ... to data structure is be ing prope rly impleme nted. Test suite The test sui te in daa.c, which is com- piled with ul e DAA_TEST d e fin e set, has 15 tests that exercise the allocation ro utines extensively. I have u-ied to vary ule tests over a range of dynamic allocations that most use rs might want to use . Each test examines dle test vari- able for the DAA o r DAAV consta nts and calls the correspo nding allocation routine. To switch from testing o ne to dle o dler, cha nge dle test variable assign me nt at th e start. Tests 1 and 2 modify dl e allocated array in a subroutine and print out assigned values in the caller. Test 4, a 10- dimensional double array, is th e largest. It takes lip dle most CPU time of any of

Articles in this issue

Archives of this issue

view archives of EETimes - Embedded Systems December 2000 Vol13_13