mirror of
https://github.com/boostorg/interprocess.git
synced 2026-01-19 04:12:13 +00:00
Intrusive:
* Added `linear<>` and `cache_last<>` options to singly linked lists. * Added `optimize_multikey<>` option to unordered container hooks. * Optimized unordered containers when `store_hash` option is used in the hook. * Implementation changed to be exception agnostic so that it can be used in environments without exceptions. * Added `container_from_iterator` function to tree-based containers. Interprocess: * Added anonymous shared memory for UNIX systems. * Fixed file lock compilation errors [SVN r44819]
This commit is contained in:
@@ -23,98 +23,93 @@ using namespace boost::interprocess;
|
||||
|
||||
int main ()
|
||||
{
|
||||
std::string process_name;
|
||||
test::get_process_id_name(process_name);
|
||||
|
||||
try{
|
||||
const std::size_t FileSize = 99999*2;
|
||||
//Create shared memory and file mapping
|
||||
windows_shared_memory mapping(create_only, process_name.c_str(), read_write, FileSize);
|
||||
|
||||
const char *names[2] = { test::get_process_id_name(), 0 };
|
||||
for(unsigned int i = 0; i < sizeof(names)/sizeof(names[0]); ++i)
|
||||
{
|
||||
const std::size_t FileSize = 99999*2;
|
||||
//Create a file mapping
|
||||
windows_shared_memory mapping(open_only, process_name.c_str(), read_write);
|
||||
windows_shared_memory mapping
|
||||
(create_only, names[i], read_write, FileSize);
|
||||
|
||||
//Create two mapped regions, one half of the file each
|
||||
mapped_region region (mapping
|
||||
,read_write
|
||||
,0
|
||||
,FileSize/2
|
||||
,0);
|
||||
{
|
||||
|
||||
mapped_region region2(mapping
|
||||
,read_write
|
||||
,FileSize/2
|
||||
,FileSize - FileSize/2
|
||||
,0);
|
||||
//Create two mapped regions, one half of the file each
|
||||
mapped_region region (mapping
|
||||
,read_write
|
||||
,0
|
||||
,FileSize/2
|
||||
,0);
|
||||
|
||||
//Fill two regions with a pattern
|
||||
unsigned char *filler = static_cast<unsigned char*>(region.get_address());
|
||||
for(std::size_t i = 0
|
||||
;i < FileSize/2
|
||||
;++i){
|
||||
*filler++ = static_cast<unsigned char>(i);
|
||||
}
|
||||
mapped_region region2(mapping
|
||||
,read_write
|
||||
,FileSize/2
|
||||
,FileSize - FileSize/2
|
||||
,0);
|
||||
|
||||
filler = static_cast<unsigned char*>(region2.get_address());
|
||||
for(std::size_t i = FileSize/2
|
||||
;i < FileSize
|
||||
;++i){
|
||||
*filler++ = static_cast<unsigned char>(i);
|
||||
}
|
||||
}
|
||||
//Fill two regions with a pattern
|
||||
unsigned char *filler = static_cast<unsigned char*>(region.get_address());
|
||||
for(std::size_t i = 0
|
||||
;i < FileSize/2
|
||||
;++i){
|
||||
*filler++ = static_cast<unsigned char>(i);
|
||||
}
|
||||
|
||||
//See if the pattern is correct in the file using two mapped regions
|
||||
{
|
||||
//Create a file mapping
|
||||
windows_shared_memory mapping(open_only, process_name.c_str(), read_write);
|
||||
mapped_region region(mapping, read_write, 0, FileSize/2, 0);
|
||||
mapped_region region2(mapping, read_write, FileSize/2, 0/*FileSize - FileSize/2*/, 0);
|
||||
|
||||
unsigned char *checker = (unsigned char*)region.get_address();
|
||||
//Check pattern
|
||||
for(std::size_t i = 0
|
||||
;i < FileSize/2
|
||||
;++i){
|
||||
if(*checker++ != static_cast<unsigned char>(i)){
|
||||
return 1;
|
||||
filler = static_cast<unsigned char*>(region2.get_address());
|
||||
for(std::size_t i = FileSize/2
|
||||
;i < FileSize
|
||||
;++i){
|
||||
*filler++ = static_cast<unsigned char>(i);
|
||||
}
|
||||
}
|
||||
|
||||
//Check second half
|
||||
checker = (unsigned char *)region2.get_address();
|
||||
//See if the pattern is correct in the file using two mapped regions
|
||||
{
|
||||
mapped_region region (mapping, read_only, 0, FileSize/2, 0);
|
||||
mapped_region region2(mapping, read_only, FileSize/2, FileSize - FileSize/2, 0);
|
||||
|
||||
//Check pattern
|
||||
for(std::size_t i = FileSize/2
|
||||
;i < FileSize
|
||||
;++i){
|
||||
if(*checker++ != static_cast<unsigned char>(i)){
|
||||
return 1;
|
||||
unsigned char *checker = (unsigned char*)region.get_address();
|
||||
//Check pattern
|
||||
for(std::size_t i = 0
|
||||
;i < FileSize/2
|
||||
;++i){
|
||||
if(*checker++ != static_cast<unsigned char>(i)){
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
//Check second half
|
||||
checker = (unsigned char *)region2.get_address();
|
||||
|
||||
//Check pattern
|
||||
for(std::size_t i = FileSize/2
|
||||
;i < FileSize
|
||||
;++i){
|
||||
if(*checker++ != static_cast<unsigned char>(i)){
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Now check the pattern mapping a single read only mapped_region
|
||||
{
|
||||
//Create a file mapping
|
||||
windows_shared_memory mapping(open_only, process_name.c_str(), read_only);
|
||||
//Now check the pattern mapping a single read only mapped_region
|
||||
{
|
||||
//Create a single regions, mapping all the file
|
||||
mapped_region region (mapping, read_only);
|
||||
|
||||
//Create a single regions, mapping all the file
|
||||
mapped_region region (mapping
|
||||
,read_only);
|
||||
|
||||
//Check pattern
|
||||
unsigned char *pattern = static_cast<unsigned char*>(region.get_address());
|
||||
for(std::size_t i = 0
|
||||
;i < FileSize
|
||||
;++i, ++pattern){
|
||||
if(*pattern != static_cast<unsigned char>(i)){
|
||||
return 1;
|
||||
//Check pattern
|
||||
unsigned char *pattern = static_cast<unsigned char*>(region.get_address());
|
||||
for(std::size_t i = 0
|
||||
;i < FileSize
|
||||
;++i, ++pattern){
|
||||
if(*pattern != static_cast<unsigned char>(i)){
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(std::exception &exc){
|
||||
//shared_memory_object::remove(test::get_process_id_name());
|
||||
std::cout << "Unhandled exception: " << exc.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user