template<class elementT , typename indexT , unsigned int cookieVal, unsigned int versionVal, elementT accessorFunc, void setterFunc, size_t elementCount2BytesFunc, class arrayHeaderClass >
int MemoryMapArray< elementT, indexT, cookieVal, versionVal, accessorFunc, setterFunc, elementCount2BytesFunc, arrayHeaderClass >::create |
( |
const char * |
file, |
|
|
indexT |
elementCount, |
|
|
int |
optionalHeaderCount = 0 |
|
) |
| |
|
inline |
Create a vector with elementCount memebers.
Does administrative setup of the header and populating this class members. User will need to finish populating the contents of the metaData and data sections.
If file==NULL, the underlying allocation is done via malloc(), so that the results of write access to this vecor are not saved in a file.
If file!=NULL, a file will be created on disk, and all write accesses done via the method ::set will be persistent in that file.
Definition at line 208 of file MemoryMapArray.h.
209 {
210 size_t len = elementCount2BytesFunc(elementCount) +
211 header->getHeaderSize(optionalHeaderCount);
212 int rc;
214 if (rc)
215 {
216 std::ostringstream buf;
217 buf << file << ": failed to create file";
218 errorStr = buf.str();
219 close();
220 return rc;
221 }
222 header = (arrayHeaderClass *) MemoryMap::data;
223 header->constructorClear();
224 header->typeCookie = cookieVal;
225 header->typeVersion = versionVal;
226 header->headerSize = header->getHeaderSize(optionalHeaderCount);
227 header->elementCount = elementCount;
228 data = (char *)((char *) MemoryMap::data + header->headerSize);
229
230 const char *env;
231 char hostname[256];
232 env = getenv("USER");
233 if (env) header->setCreationUser(env);
234 header->creationDate = time(NULL);
235#if defined(_WIN32)
236 hostname[0] = '\0';
237#else
238 gethostname(hostname, sizeof(hostname));
239#endif
240 header->setCreationHost(hostname);
241 return 0;
242 }
virtual bool create(const char *file, size_t size)
create the memory mapped file on disk
References MemoryMap::create().
Referenced by MemoryMapArray< elementT, indexT, cookieVal, versionVal, accessorFunc, setterFunc, elementCount2BytesFunc, arrayHeaderClass >::create(), and GenomeSequence::loadDBSNP().