C/C++ Reference
Volatile/temporary memory used as name in a HttpDir/HttpPage

The name passed in as argument to a HttpDir/HttpPage object cannot be changed since the constructor only stores a pointer to the name. The virtual file system is designed to use as little memory as possible. Thus, the name passed in as argument to the HttpDir/HttpPage constructor is not copied; only the pointer reference is copied.

One would normally use constants as the name argument, but if you need to create a name dynamically, you can allocate space for the structure and the name as one piece as follows:

HttpDir* createDir(char* name)
{
   HttpDir* dir = baMalloc(sizeof(HttpDir) + strlen(name) + 1);
   if(dir)
   {
      char* ptr = (char*)(dir+1);
      strcpy(ptr, name);
      HttpDir_constructor(dir, ptr, 0);
   }
   return dir;
}

We use a HttpDir in the example above, but it also applies to a HttpPage, HttpResRdr, AuthenticateDir, EvDir or any class derived from HttpPage or HttpDir.