Currently viewing: GipsySoft » Front Page» Articles


Simple class that stores randomly sized chunks of data in a file. This is useful when you want to store, retrieve, delete and recycle random sized blocks. I use it along side a simple index.

Creates two files, one named the same as the actual file passed and the other with teh extension 'r'. the filename.r file contains the list of free items.

Tested in UNICODE.


//	Create the file pair
RandomFile::CRandomFile f( _T("d:\\test") );

//	Create a block to add into the file
RandomFile::BLOCKLENGTH lBlockSize = GetRandomBlockSize();
char *p = new char[ lBlockSize ];

//	Add the block, and if successful add the 'handle' into our own index
RandomFile::RANDOMHANDLE hHandle;
if( f.AddBlock( p, lBlockSize, hHandle ) )
	arrIndex.Add( hHandle );
delete[] p;


Click to view the source code