[sldev] Re: Reformatting Textures for the cache

Argent Stonecutter secret.argent at gmail.com
Tue Mar 27 06:14:30 PDT 2007


> I couldn't disagree more.  In redesigning the cache system we must  
> presume
> that the user we are writing for is running a hugely fragmented  
> FAT32 drive
> and a file open in a 10,000 file directory will take 10,000 times  
> longer
> than a file open in a 1 file directory (so maybe I exaggerate).

// N_LEVELS * N_CHARS should probably not be greater than 8, since  
there's a
// separator in the UUID there.
#define N_LEVELS 2
// UUID is hex, so 2 chars means maximum of 256 directories per level
#define N_CHARS 2

#ifdef I_KNOW_THIS_ITS_A_UNIX_SYSTEM
# define DIR_SEP '/'
#else
# define DIR_SEP '\\'
#endif

extern char *cache_dir;
extern int safe_make_directory_path(char *path);

FILE *fopen_texture(char *filename, char *mode)
{
   int l = strlen(cache_dir);
   int m = strlen(filename);
   char *new_filename = calloc(l + 1 + m + N_LEVELS * (N_CHARS + 1) +  
1);
   char *s, *t;
   int i, j;

   if (!new_filename) return NULL;

   s = filename;
   t = new_filename;
   strcpy(t, cache_dir);
   t += l;

   for (i = 0; *s && i < N_LEVELS; i++)
   {
     *t++ = DIR_SEP;
     for (j = 0; *s && j < N_CHARS; j++)
       *t++ = *s++;
   }
   *t = NULL;
   if (!safe_make_directory_path(new_filename)) return NULL;
   *t++ = DIR_SEP;

   strcpy(t, filename);

   return fopen(new_filename, mode);
}

> If we want to rely on file system functionality we are going to  
> have to look
> at file-system-in-a-file solutions - perhaps using something third  
> party
> rather than dusting off the VFS - but not relying on direct file  
> system
> storage unless we can prove that that is the best option _on FAT32_.

See above code (note, only desk checked, test before use).



More information about the SLDev mailing list