I'm mapping a file view to share an array of 200 std::strings between two processes but I've been getting an access violation error when I write a string longer than 15 characters into the array. Does anyone know how I might increase the size of each array element so it doesn't overflow and cause problems?
struct _sSharedArray {
std::string strData[ 200 ];
} *sSharedArray = NULL;
HANDLE sSeedFileHandle;
HANDLE sFileMappingHandle;
sSeedFileHandle = CreateFile( "C:\\Seed.file" , GENERIC_READ | GENERIC_WRITE , FILE_SHARE_READ | FILE_SHARE_WRITE , 0 , CREATE_ALWAYS , FILE_ATTRIBUTE_HIDDEN , 0 );
sFileMappingHandle = CreateFileMapping( sSeedFileHandle , 0 , PAGE_READWRITE , 0 , 10000 , "sSharedMap" );
sFileMappingHandle = OpenFileMapping( FILE_MAP_WRITE , 1 , "sSharedMap" );
sSharedArray = ( struct _sSharedArray* ) MapViewOfFile( sFileMappingHandle , FILE_MAP_WRITE , 0 , 0 , 0 );
MapViewOfFile returns the starting address of the mapped view so I set that to the starting address of the array.
Now if I write a string into the array...
sSharedArray->strData[x] = "This string will cause an access violation!";
sSharedArray->strData[x] = "This will not.";
Note : Error checking and comments removed.