Nat (Padmanabhan Natarajan) wrote: > Hi Gene, > > Its interesting that you have mentioned about cache/page misses. Would it > really matter since this is a linked list and its likely that the nodes are > already in random locations in the memory. > > Regards, > Nat >
If you have a program with very complex heap usage, then you're right. But malloc() implementations tend to allocate successive nodes in ascending address order. So in many cases you'll end up with access in address order. Here's an example: int main(void) { int i; struct node_t { struct node_t *next; int data; } *p; for (i = 0; i < 20; i++) { p = malloc(sizeof(struct node_t)); printf("%p\n", p); } return 0; } Output with gcc: 003D3F68 003D2430 003D2440 003D2450 003D2460 003D2470 003D2480 003D2490 003D24A0 003D24B0 003D24C0 003D24D0 003D24E0 003D24F0 003D2500 003D2510 003D2520 003D2530 003D2540 003D2550 Output with Visual C v6: 00320F60 00320F78 00320F90 00320FA8 00320FC0 00320FD8 00320FF0 00321008 00321020 00321038 00321050 00321068 00321080 00321098 00322D10 00322D28 00322D40 00322D58 00322D70 00322D88 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/algogeeks -~----------~----~----~----~------~----~------~--~---