c - Linked List in Contiguous Memory Space -


i have been looking code measuring latencies , 1 of methods came across deals iterating through linked list confined dynamically allocated memory space. understand traditional linked lists pretty , understand dynamically allocated arrays, putting 2 throwing me through loop. may seem relatively basic question not great c , whatever reason having hard time constructing it.

i wanted make strides of 128 bytes tried doing following (i know way off base needed start somewhere)

char** randomarray = malloc(accesssize);    //allocate space linked list char** start=randomarray;               //header base adress char** iterate;                         //iterator char** end =randomarray+accesssize;     //end address for(iterate=start; iterate < end; iterate+=128){     *iterate = iterate+128;                 //step through in strides of 128 bytes, assign next addr current value }  *iterate=start;     //linked list circular, assign last element first 

i had no idea data type point to, allocate space struct space exists.

i thought iterate through follows

for(counter = 0; counter < lotsofaccess; counter++){      start = (char**) *start; } 

well didn't work me , can't seem find out why. have suggestions proper way of implementing or might doing wrong?

well did't many bites on 1 still think useful question post did!

to create linked list strides of 128 bytes in dynamically allocated space did:

char * randomarray = malloc(accesssize*sizeof(char)); int counter; char ** head = (char **) randomarray; char ** iterate = head; for(counter=0; counter < accesssize; counter+=128){     (*iterate) = &randomarray[counter+128];     iterate+=(128/sizeof iterate); } *iterate = head; 

to traverse did:

iterate = head;    for(counter=0; counter < num_accesses; counter++){     iterate = *iterate; } 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -