Using a link list over an array.



Hi, I am wondering which of the two data structures (link list or
array) would be better in my situation. I have to create a list of
rays for my ray tracing program.

the data structure of ray looks like this:


typedef struct
{
vector origin; /* vector is an array of 3 doubles */
vector efield;
double t;
vector direction;
}ray;

I need a very fine grid of rays i.e. something like 15-20 millions of
such rays. Many a times my program fails and reports less memory when
I use an array because there are data structures to be stored as well.

with an array eg. raylist[some_size] when i trace the rays, i do the
following :

for(count = 0; count < numberofrays; count++)
{
/* trace the ray raylist[i] */
}

I realized that once a ray was traced, it had no further use in the
program so it was unnecessarily occupying that memory which can be
utilized elsewhere.

I was thinking that using a link list may help my situation a little
bit here.

ray *p;
ray *q;
p = ray_list_head_ptr; /* ray_list_head_ptr points to the first node
in link list */

while( p != NULL)
{
/* trace the ray pointed by p */
q = p;
p = p->next;
/* Now the ray pointed by q is of no use so free that memory and
make the node pointed by p as the first node of the ray list */
free(q);
ray_list_head_ptr = p;
}
.



Relevant Pages

  • Re: 2D array of structures
    ... And your program is messing around with memory in bad ways. ... allocate memory for the menu strings each time round. ... include a complete redesign of the data structures. ... assign a pointer to the relevant element of that array to the name member), ...
    (comp.lang.c)
  • Re: Memory usage warning
    ... "Ray" wrote in message ... > The store.exe process is allocating more memory than usual. ... > Notifications task in the Server Management Monitoring and Reporting ...
    (microsoft.public.windows.server.sbs)
  • Re: Innocent!
    ... >> outclassed by my comments and my replies. ... >"An education isn't how much you have committed to memory, ... >Gee, now who displays this characteristic of being educated (which ... Ray -- or ER? ...
    (misc.writing)
  • Re: problem with output of the program on different OS
    ... You are creating a huge array in ... the amplitude of electrical field is now of the complex form: ... This is for direct ray when the ray is travelling from the source to ... from where the reflected ray starts), is distance travelled and RM is ...
    (comp.lang.c)
  • Re: Virtual Memory
    ... I don't see a post from ray telling me what to do to change it FN. ... thought I would have to *buy* (get from Bram) more RAM ... Someone suggested that virtual memory should be set to about ... But I agree that for Windows XP it would be best to fit 1Gb of real ...
    (uk.people.silversurfers)