C help

Associate
Joined
30 Jun 2003
Posts
2,237
Location
Sussex
okay. a few questions here. i'll say how i'd do it and you can laugh and correct.

i want a library of images in a dynamically-managed data structure.

so as we don't know the sizes of size and pixels:

Code:
struct image{
  char name[MAX_NAME_SIZE];
  int size;
  float pixels[MAX_IMG_SIZE]
};

would pointers be better?

then would an double-linked list suffice for the data structure? it has be able to have an entry added, and deleted by name.
 
Pointers would be better for the image pixels, yes, as I'm sure you can appreciate decent size images can take a fair amount of space and as soon as you start working with a few images in your list you'll run out of stack space. Using pointers for this will store the pixel data on the heap, on which there is much more space.

Ideally, for storage if you are adding/deleting by name you'd want to be looking at a hash table. However a less efficient (but simpler) way to do it would be to use a simple linked list with functions for searching for an image by name. It doesn't really need to be doubley-linked unless you really need it to be.
 
Back
Top Bottom